Unable to create .mde file

  • Thread starter Lee Stafford via AccessMonster.com
  • Start date
L

Lee Stafford via AccessMonster.com

I know, compile the vba code.....I have searched this topic til fingers got
numb and that is the solution that everyone gives, but it doesn't solve my
problem.

When I try to open the front end, sometimes it will hang up on a bit of code
that is in the switchboard. The following is the code:

Private Sub Form_Activate()

'When the database is opened display welcome user message.
'When the timer interval is reached, this form closes and opens Switchboard

If Time() < 0.5 Then
[lblmorning].Visible = True
[lblafternoon].Visible = False
[lblevening].Visible = False

ElseIf Time() > 0.5 And Time() < 0.75 Then
[lblmorning].Visible = False
[lblafternoon].Visible = True
[lblevening].Visible = False

ElseIf Time() > 0.75 Then
[lblmorning].Visible = False <--This is where it hangs up (it
is 8:30pm when running it.)
[lblafternoon].Visible = False
[lblevening].Visible = True
End If
End Sub


Runtime error 91
object variable or with block variable not set.

Sometimes it doesn't hang up there. It doesn't give me the option to compile,
I just reset it and it is fine. The compile option is greyed out. It has
never had this problem with this code before.

Can anyone shed some light?

Thanks,

Lee
 
T

tina

well, i can't see any obvious reason for the code to err - especially to err
only intermittently. i did notice that you said the code runs in the
switchboard form - but the commented notes in the code state that the
current form's timer event code closes the form and opens the switchboard
form. so i'm assuming you meant that the the posted code actually runs in
the "welcome message" form.

you might try any or all of the following:

1) move the code from the form's Activate event to the Load event.

2) remove the parens from the Time function, as
If Time < 0.5 Then

instead of
If Time() < 0.5 Then

3) make sure your If statements are inclusive, as
If Time < 0.5 Then
ElseIf Time >= 0.5 And Time() <= 0.75 Then
ElseIf Time > 0.75 Then

4) use one label instead of three (setting the label's Visible property to
True *in form design view*), and change the label's caption, instead of
hiding/showing multiple labels, as

Select Case Time
Case Is < 0.5
[lblmorning].Caption = "Good morning"
Case 0.5 To 0.75
[lblmorning].Caption = "Good afternoon"
Case Is > 0.75
[lblmorning].Caption = "Good evening"
End Select

other than that, suggest you open the database while bypassing Startup, set
a Break on the welcome form's code, and then open the welcome form manually
so you can step through the code and see exactly where it's erring out
(sometimes the highlighted line is *not* the source of the problem). this
may not give you any useful information, since the code only errs
intermittently, but may be worth a try.

hth


Lee Stafford via AccessMonster.com said:
I know, compile the vba code.....I have searched this topic til fingers got
numb and that is the solution that everyone gives, but it doesn't solve my
problem.

When I try to open the front end, sometimes it will hang up on a bit of code
that is in the switchboard. The following is the code:

Private Sub Form_Activate()

'When the database is opened display welcome user message.
'When the timer interval is reached, this form closes and opens Switchboard

If Time() < 0.5 Then
[lblmorning].Visible = True
[lblafternoon].Visible = False
[lblevening].Visible = False

ElseIf Time() > 0.5 And Time() < 0.75 Then
[lblmorning].Visible = False
[lblafternoon].Visible = True
[lblevening].Visible = False

ElseIf Time() > 0.75 Then
[lblmorning].Visible = False <--This is where it hangs up (it
is 8:30pm when running it.)
[lblafternoon].Visible = False
[lblevening].Visible = True
End If
End Sub


Runtime error 91
object variable or with block variable not set.

Sometimes it doesn't hang up there. It doesn't give me the option to compile,
I just reset it and it is fine. The compile option is greyed out. It has
never had this problem with this code before.

Can anyone shed some light?

Thanks,

Lee
 
L

Lee Stafford via AccessMonster.com

Those are excellent suggestions. I will try them. They sound like if
anything, they will at least clean up the code a bit. Thanks a lot.

you might try any or all of the following:

1) move the code from the form's Activate event to the Load event.

2) remove the parens from the Time function, as
If Time < 0.5 Then

instead of
If Time() < 0.5 Then

3) make sure your If statements are inclusive, as
If Time < 0.5 Then
ElseIf Time >= 0.5 And Time() <= 0.75 Then
ElseIf Time > 0.75 Then

4) use one label instead of three (setting the label's Visible property to
True *in form design view*), and change the label's caption, instead of
hiding/showing multiple labels, as

Select Case Time
Case Is < 0.5
[lblmorning].Caption = "Good morning"
Case 0.5 To 0.75
[lblmorning].Caption = "Good afternoon"
Case Is > 0.75
[lblmorning].Caption = "Good evening"
End Select
 
T

tina

you're welcome, and good luck :)


Lee Stafford via AccessMonster.com said:
Those are excellent suggestions. I will try them. They sound like if
anything, they will at least clean up the code a bit. Thanks a lot.

you might try any or all of the following:

1) move the code from the form's Activate event to the Load event.

2) remove the parens from the Time function, as
If Time < 0.5 Then

instead of
If Time() < 0.5 Then

3) make sure your If statements are inclusive, as
If Time < 0.5 Then
ElseIf Time >= 0.5 And Time() <= 0.75 Then
ElseIf Time > 0.75 Then

4) use one label instead of three (setting the label's Visible property to
True *in form design view*), and change the label's caption, instead of
hiding/showing multiple labels, as

Select Case Time
Case Is < 0.5
[lblmorning].Caption = "Good morning"
Case 0.5 To 0.75
[lblmorning].Caption = "Good afternoon"
Case Is > 0.75
[lblmorning].Caption = "Good evening"
End Select
 
L

Lee Stafford via AccessMonster.com

tina said:
you're welcome, and good luck :)
Those are excellent suggestions. I will try them. They sound like if
anything, they will at least clean up the code a bit. Thanks a lot.
[quoted text clipped - 26 lines]
[lblmorning].Caption = "Good evening"
End Select

They did work. I used the Select statement that you had suggested. It did
work. No more errors.
Thanks again.
 
T

tina

oh, good, glad that cleared up the problem! :)


Lee Stafford via AccessMonster.com said:
tina said:
you're welcome, and good luck :)
Those are excellent suggestions. I will try them. They sound like if
anything, they will at least clean up the code a bit. Thanks a lot.
[quoted text clipped - 26 lines]
[lblmorning].Caption = "Good evening"
End Select

They did work. I used the Select statement that you had suggested. It did
work. No more errors.
Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top