Catching Errors

csdrex87

Registered User.
Local time
Today, 13:51
Joined
Jul 1, 2009
Messages
66
Hey I'm writing this prompt box and I want to have it check to see if there is anything entered in the drop down menu except what is supposed to be there. If so I would like for it to do a MsgBox saying error please put something in ... yadda yadda. My problem is every thing that i have tried to check for the value of the strings has not worked because of syntax. If you could help me it would be greatly appreciated.

code:
If ("[Forms!PromptBox!FormName]" = "EmployeeDaily" Or "EmployeeWeekly" Or "EmployeeInformation" Or "Forecast" Or "OrderRegister") Then
If (MsgBox("Please select one of the options from below.", vbOKOnly, "Cancel") = vbOK) Then
Cancel = True
End If
End If
 
Use a Select Case statement instead:

Code:
Select Case Forms!PromptBox.FormName
   Case "EmployeeDaily", "EmployeeWeekly", "EmployeeInformation", "Forecast", "OrderRegister"
      Cancel = True
      MsgBox("Please select one of the options from below.", vbOKOnly, "Cancel"
End Select
Your Message box does not need the IF ... = vbOK as you currently can only click OK so it isn't necessary to check to see if it is checked.
 
I am actually getting a syntax error by not having it equal to something. it keeps telling me that it is getting a compile error expected list separator or ).
Then if i put a ) in it expects me to put an = (expression)
Any suggestions?
 
Sorry, I missed removing the other paren..

this -

MsgBox("Please select one of the options from below.", vbOKOnly, "Cancel"

should be

MsgBox "Please select one of the options from below.", vbOKOnly, "Cancel"
 
Ah its backwards. I want those words to allow it to go through and if anything else is put in for it to give the error message.

That was my original problem is finding a not equal to operator... even searching on the web i couldnt find anyhting like that
 
Okay, go ahead with this:
Code:
Select Case Forms!PromptBox.FormName
   Case "EmployeeDaily", "EmployeeWeekly", "EmployeeInformation", "Forecast", "OrderRegister"
[COLOR=red][B]   Case Else[/B][/COLOR]
      Cancel = True
      MsgBox "Please select one of the options from below.", vbOKOnly, "Cancel"
End Select
 
(The only reason i need this is im getting errors when they try to open a form that isn't available)
Not quite sure why its happening but regardless of what i enter it is now executing case else then going on with the code :-(. So even on the drop down menu items i'm getting errors... this is what its changed to

Code:

Dim intCaseN As Integer

CaseN = Forms!formUserLoginAccess!txtUSL

Select Case Forms!PromptBox.FormName
Case "EmployeeDaily", "EmployeeWeekly", "EmployeeInformation", "Forecast", "OrderRegister"
Case Else
Cancel = True
MsgBox "Please select one of the options from below.", vbOKOnly, "Cancel"
End Select

Select Case CaseN
Case 1
DoCmd.OpenForm Forms!PromptBox!FormName, acNormal
DoCmd.GoToRecord , , acNewRec
DoCmd.Close acForm, "formMenuBar"
DoCmd.Close acForm, "PromptBox"

Case 2
DoCmd.OpenForm Forms!PromptBox!FormName, , , , acFormEdit And Forms!YourFormNameHere.AllowEdits = False And Forms!YourFormNameHere.AllowDeletions = False
DoCmd.GoToRecord , , acNewRec
DoCmd.Close acForm, "formMenuBar"
DoCmd.Close acForm, "PromptBox"

Case 3
DoCmd.OpenForm Forms!PromptBox!FormName, acNormal, , , acFormReadOnly
DoCmd.GoToRecord , , acNewRec
DoCmd.Close acForm, "formMenuBar"
DoCmd.Close acForm, "PromptBox"

Case 4
If MsgBox("You do not have sufficient access to this database!", vbOKOnly, "Restricted Access") = vbOK Then DoCmd.Quit

End Select
 
What event are you using this on?

Also, put a breakpoint at the Select Case part and see what is actually being passed. It may not be what you expect.
 
I'm doing this on a button. What this is is a separate form from menu.
The user clicks the menu button and it brings up this form which contains a drop down menu of items as well as 2 buttons. Go and Cancel. The go button executes this code and the cancel executes the DoCmd.Close code.

After doing the breakpoint The code executes and regardless of what I'm putting in im still getting the error message and no cancel. Should i use Exit Sub instead?
 
You can't issue a Cancel = True on a button click event. It isn't going to do anything.

To validate entry you need to use the form's BEFORE UPDATE event.
 
So perhaps I should put the code on the before update and then instead of doing this code i could use a Dcount function to cross check if it is in the other table?
 

Users who are viewing this thread

Back
Top Bottom