Form code runs too quickly

I have the following code attached to my form - works fine other than when 
the form is first opened. If the third "if" is true, the code runs before 
the form is even open!

Any way to have the form open first before the message box displays?

Just one more small point - what syntax do I use to have the message in the 
message box show on two lines and also have double quotes around "Job 
Complete" (as I have just typed)?

Private Sub Form_Current()
    If IsNull(txtDateCollected) Then
        Me.lblJobComplete.Visible = False
        Me.chkJobComplete.Visible = False
    ElseIf Not IsNull(txtDateCollected) And Me.chkJobComplete = True Then
        Exit Sub
    ElseIf Not IsNull(txtDateCollected) And _
        Not IsNull(Forms![Finalise 
Jobs]![FinaliseJobDetailsSubform].Form.cboRepairer1) Then
        Me.lblJobComplete.Visible = True
        Me.chkJobComplete.Visible = True
        MsgBox "If this job is now complete check the Job Complete check 
box", vbOKCancel
        Me.chkJobComplete.SetFocus
    End If
End Sub

Thanks
Sandy
 

0
Sandy
1/26/2008 9:41:51 PM
access 16762 articles. 3 followers. Follow

4 Replies
589 Views

Similar Articles

[PageSpeed] 39

Sandy:  Someone else may have a slicker way to deal with this, but when I 
want to slow down the action I use a Pause Function (adapted from another 
forum suggestion).  Place this in a module:

Public Function Pause(PauseSeconds As Integer)
Dim Start
Start = Timer
Do While Timer < Start + PauseSeconds
    DoEvents
Loop
End Function

Then place Pause 1, for example, in your code to pause for a second.  Change 
the pause amount to your liking.

To get the double quotes in the message, do this:


MsgBox "If this job is now complete check the " & Chr(34) & "Job Complete" & 
Chr(34) & " check box", vbOKCancel

HTH

JoeD

"Sandy" wrote:

> I have the following code attached to my form - works fine other than when 
> the form is first opened. If the third "if" is true, the code runs before 
> the form is even open!
> 
> Any way to have the form open first before the message box displays?
> 
> Just one more small point - what syntax do I use to have the message in the 
> message box show on two lines and also have double quotes around "Job 
> Complete" (as I have just typed)?
> 
> Private Sub Form_Current()
>     If IsNull(txtDateCollected) Then
>         Me.lblJobComplete.Visible = False
>         Me.chkJobComplete.Visible = False
>     ElseIf Not IsNull(txtDateCollected) And Me.chkJobComplete = True Then
>         Exit Sub
>     ElseIf Not IsNull(txtDateCollected) And _
>         Not IsNull(Forms![Finalise 
> Jobs]![FinaliseJobDetailsSubform].Form.cboRepairer1) Then
>         Me.lblJobComplete.Visible = True
>         Me.chkJobComplete.Visible = True
>         MsgBox "If this job is now complete check the Job Complete check 
> box", vbOKCancel
>         Me.chkJobComplete.SetFocus
>     End If
> End Sub
> 
> Thanks
> Sandy
>  
> 
0
Utf
1/26/2008 11:53:00 PM
Sandy,
when you put some code in the current event for the form, that code will run 
while the form is open and loading and will have finished running by the 
time the form has finished opening. You can't change this behaviour of 
Access. If you want the user to only see the message after the form opens, 
you will need to remove the message box from the current event. One 
suggestion is to use a label instead of a message box. Make the label 
visible or hide it depending on the values.
Another suggestion is to use a form to replace the message box.

Jeanette Cunningham

"Sandy" <sandy_stephen@DELETEhotmail.com> wrote in message 
news:D2CF69B1-8A9D-4807-AC04-AD897813892B@microsoft.com...
>I have the following code attached to my form - works fine other than when 
>the form is first opened. If the third "if" is true, the code runs before 
>the form is even open!
>
> Any way to have the form open first before the message box displays?
>
> Just one more small point - what syntax do I use to have the message in 
> the message box show on two lines and also have double quotes around "Job 
> Complete" (as I have just typed)?
>
> Private Sub Form_Current()
>    If IsNull(txtDateCollected) Then
>        Me.lblJobComplete.Visible = False
>        Me.chkJobComplete.Visible = False
>    ElseIf Not IsNull(txtDateCollected) And Me.chkJobComplete = True Then
>        Exit Sub
>    ElseIf Not IsNull(txtDateCollected) And _
>        Not IsNull(Forms![Finalise 
> Jobs]![FinaliseJobDetailsSubform].Form.cboRepairer1) Then
>        Me.lblJobComplete.Visible = True
>        Me.chkJobComplete.Visible = True
>        MsgBox "If this job is now complete check the Job Complete check 
> box", vbOKCancel
>        Me.chkJobComplete.SetFocus
>    End If
> End Sub
>
> Thanks
> Sandy
>
> 


0
Jeanette
1/27/2008 1:29:43 AM
Nice solution, Jeanette! I've seen this question come up a number of times
over the years without a successful resolution. And mimicing the messagebox
with a popup form also has the advantage of allowing much more in the way of
formatting than a real messagebox does!

Linq

-- 
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via http://www.accessmonster.com

0
Linq
1/27/2008 4:50:47 AM
Hi Joe D, Jeanette, Linq,

Firstly, sorry for delay in coming back to you all, but I had problems with 
my computer - fixed now though!

Sadly Joe, the pause function only delays the code from running and still 
does not allow the form to open first.

However if I include the following at the top of my code-

Dim strFrmName As String
    strFrmName = "Finalise Jobs"

            DoCmd.OpenForm strFrmName

the form and the message box appear simultaneously which is a much better 
result! Don't fully understand why it works (even when the form is already 
open and a different record is selected) but it does.

Thanks for all your responses and I thought you might be interested in my 
resolution.
Sandy


"Jeanette Cunningham" <nnn@discussions.microsoft.com> wrote in message 
news:#WyWnSIYIHA.6044@TK2MSFTNGP05.phx.gbl...
> Sandy,
> when you put some code in the current event for the form, that code will 
> run while the form is open and loading and will have finished running by 
> the time the form has finished opening. You can't change this behaviour of 
> Access. If you want the user to only see the message after the form opens, 
> you will need to remove the message box from the current event. One 
> suggestion is to use a label instead of a message box. Make the label 
> visible or hide it depending on the values.
> Another suggestion is to use a form to replace the message box.
>
> Jeanette Cunningham
>
> "Sandy" <sandy_stephen@DELETEhotmail.com> wrote in message 
> news:D2CF69B1-8A9D-4807-AC04-AD897813892B@microsoft.com...
>>I have the following code attached to my form - works fine other than when 
>>the form is first opened. If the third "if" is true, the code runs before 
>>the form is even open!
>>
>> Any way to have the form open first before the message box displays?
>>
>> Just one more small point - what syntax do I use to have the message in 
>> the message box show on two lines and also have double quotes around "Job 
>> Complete" (as I have just typed)?
>>
>> Private Sub Form_Current()
>>    If IsNull(txtDateCollected) Then
>>        Me.lblJobComplete.Visible = False
>>        Me.chkJobComplete.Visible = False
>>    ElseIf Not IsNull(txtDateCollected) And Me.chkJobComplete = True Then
>>        Exit Sub
>>    ElseIf Not IsNull(txtDateCollected) And _
>>        Not IsNull(Forms![Finalise 
>> Jobs]![FinaliseJobDetailsSubform].Form.cboRepairer1) Then
>>        Me.lblJobComplete.Visible = True
>>        Me.chkJobComplete.Visible = True
>>        MsgBox "If this job is now complete check the Job Complete check 
>> box", vbOKCancel
>>        Me.chkJobComplete.SetFocus
>>    End If
>> End Sub
>>
>> Thanks
>> Sandy
>>
>>
>
> 
0
Sandy
1/31/2008 4:41:19 PM
Reply:

Similar Artilces: