how to pause during onClick event??

T

tlyczko

I have a form with four controls:

cboTopic (choose a topic)
dtmTrainingDate (text, date entry)
mslbxTest (multiple select box, choose names)
cmdUpdateDatabase (button, clicking processes all the form code to
review data and update the database)

When the user clicks cmdUpdateDatabase, the evaluation of the first
three controls occurs.
For example,

If IsNull(Me.cboTopic.Value) Or Me.cboTopic.Value = 0 Then
Call MsgBox("Please select a topic from the drop-down list.",
vbExclamation, "Select Topic")
Me.cboTopic.SetFocus
End If

If Me.dtmTrainingDate.Value > Now() Then
Call MsgBox("You've entered a date or year in the future. Please
enter a valid training date.", vbExclamation, "Enter Date")
Me.dtmTrainingDate.SetFocus
End If

If Me.mslbxTest.ItemsSelected.Count = 0 Then
Call MsgBox("Please make a selection from the list.",
vbExclamation, "Select Names")
Me.mslbxTest.SetFocus
End If

The problem is that the message boxes appear, one by one, but the
onClick event code does not pause until later, it keeps processing, it
doesn't let the user go back to the form.

I want the onClick code to pause immediately if any of these conditions
occur, and send the user back to the form to fix it.

I tried putting 'On Error Resume Next' before the SetFocus lines, but
that does not work.

How do I make the Access code stop to permit the user to fix his/her
mistake, then continue processing??

Thank you,
:) tom
 
G

Graham Mandeno

Hi Tom

The easiest way around this is to exit from the Click event procedure as
soon as the first problem is detected. To do this, add the following line
after each of your SetFocus statements:
Exit Sub
 
S

Sandra Daigle

Hi Tom,

You have to handle this by structuring the code correctly. Using
if..then..elsif statements you can ensure that if the first condition fails,
the remaining conditions are skipped:

For example:

If IsNull(Me.cboTopic.Value) Or Me.cboTopic.Value = 0 Then
Call MsgBox("Please select a topic from the drop-down list.",
vbExclamation, "Select Topic")
Me.cboTopic.SetFocus
elseif Me.dtmTrainingDate.Value > Now() Then
Call MsgBox("You've entered a date or year in the future. Please enter
a valid training date.", vbExclamation, "Enter Date")
Me.dtmTrainingDate.SetFocus
elseif Me.mslbxTest.ItemsSelected.Count = 0 Then
Call MsgBox("Please make a selection from the list.", vbExclamation,
"Select Names")
Me.mslbxTest.SetFocus
End If
 
T

tlyczko

Thank you, everyone, I'm not sure about the elseif, but I get the
general idea.
I can setfocus and then exit sub...
I will try these things.
Thank you,
Tom
 

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