Custom error message

SueBK

Registered User.
Local time
Tomorrow, 00:41
Joined
Apr 2, 2009
Messages
197
I have a form with a drop down box and a button. The user chooses a project from the drop down; clicks the button and a 2nd form opens with the details for the chosen project.

I would like to put an error message on the button. At the moment if there is no project chosen an error message comes up that is uninterpretable by the average English speaker ;)

I would like it to instead say "Please choose a project". I assume this would be a fairly simple line added to the current 'on click' code?
 
Presumably the combo starts out Null, so

Code:
If IsNull(Me.ComboName) Then
  MsgBox "Please choose an item"
Else
  DoCmd.OpenForm...
End If
 
I have no code attached to the combobox; only to the command button. My command button code is:

Private Sub Command47_Click()
On Error GoTo Err_Command47_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmProjectMaster"

stLinkCriteria = "[ProjectID]=" & Me![StartCombo01]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_Command47_Click:
Exit Sub
Err_Command47_Click:
MsgBox Err.Description
Resume Exit_Command47_Click
 
If you follow pbaldy suggestion your code should look like this:

Private Sub Command47_Click()
On Error GoTo Err_Command47_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmProjectMaster"

If IsNull(Me![StartCombo01]) Then
MsgBox "Please choose an item"
Else
stLinkCriteria = "[ProjectID]=" & Me![StartCombo01]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Exit_Command47_Click:
Exit Sub
Err_Command47_Click:
MsgBox Err.Description
Resume Exit_Command47_Click

Have a good day. Cheers!
 
A far more efficient way is to make your button disabled (.Enabled = False) then on the AfterUpdate of the Combo Box change that to .Enabled = True. This means that the user cannot click on the button unless a project is selected, and as such it does away with the need to trap the error.

David
 
A far more efficient way is to make your button disabled (.Enabled = False) then on the AfterUpdate of the Combo Box change that to .Enabled = True. This means that the user cannot click on the button unless a project is selected, and as such it does away with the need to trap the error.

David
Then the user is left frustrated and wondering why the button doesn't work
 

Users who are viewing this thread

Back
Top Bottom