Help with error message please

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I don't know very much about VB so please be gentle with me!
I have a form with drop down selector list and then a command button which
opens another form with the record chosen from the drop down list. I created
the command button code using the wizard so looks like this
Private Sub OK_Click()
On Error GoTo Err_OK_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "F_Delete Contact"

stLinkCriteria = "[Company Number]=" & Me![Choose Company]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_OK_Click:
Exit Sub

Err_OK_Click:
MsgBox err.procedure
Resume Exit_OK_Click

This works fine but if the user just clicks the button without making a
selection comes up with standard error message. I'd like to replace this
message with a prompt that says 'You must select Company first' with an OK
button that then takes them back to the selection box. What's the best (and
easiest) way to do this please.
Thanks - Sheila
 
By adding a check if no value was entered

Private Sub OK_Click()
On Error GoTo Err_OK_Click

Dim stDocName As String
Dim stLinkCriteria As String
If IsNull(Me![Choose Company]) Then
Msgbox "You must select Company first"
Else
stDocName = "F_Delete Contact"

stLinkCriteria = "[Company Number]=" & Me![Choose Company]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

Exit_OK_Click:
Exit Sub

Err_OK_Click:
MsgBox err.procedure
Resume Exit_OK_Click
 
Fantastic - thanks

Ofer Cohen said:
By adding a check if no value was entered

Private Sub OK_Click()
On Error GoTo Err_OK_Click

Dim stDocName As String
Dim stLinkCriteria As String
If IsNull(Me![Choose Company]) Then
Msgbox "You must select Company first"
Else
stDocName = "F_Delete Contact"

stLinkCriteria = "[Company Number]=" & Me![Choose Company]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

Exit_OK_Click:
Exit Sub

Err_OK_Click:
MsgBox err.procedure
Resume Exit_OK_Click

--
Good Luck
BS"D


Sheila D said:
Hi

I don't know very much about VB so please be gentle with me!
I have a form with drop down selector list and then a command button which
opens another form with the record chosen from the drop down list. I created
the command button code using the wizard so looks like this
Private Sub OK_Click()
On Error GoTo Err_OK_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "F_Delete Contact"

stLinkCriteria = "[Company Number]=" & Me![Choose Company]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_OK_Click:
Exit Sub

Err_OK_Click:
MsgBox err.procedure
Resume Exit_OK_Click

This works fine but if the user just clicks the button without making a
selection comes up with standard error message. I'd like to replace this
message with a prompt that says 'You must select Company first' with an OK
button that then takes them back to the selection box. What's the best (and
easiest) way to do this please.
Thanks - Sheila
 

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

Back
Top