Unwanted Message Box

D

Deb

I'm sure this is a simple thing, and I'm quite sure I've left something out
of my code (below)

Private Sub cboPartNo_NotInList(NewData As String, Response As Integer)
Dim strMsg As String
Dim ctl As Control
Set ctl = Screen.ActiveControl

strMsg = "The Part Number you entered, " & NewData & ", is not in the Part
Number List!" & _
vbCrLf & "Do you want to add it?"
If MsgBox(strMsg, vbYesNo, "Not listed") = vbYes Then

DoCmd.OpenForm "frm_PartNumbers"
Else
ctl.Undo
Response = acDataErrContinue
End If
End Sub

The code works just fine with the exception that when the form opens up for
entering the new part number information, an Access Message Box pops up and
indicates that the number entered in the combo box is not in the Part No
List, and wants the user to pick from the list. How do I keep this message
box from opening?
 
D

Dirk Goldgar

Deb said:
I'm sure this is a simple thing, and I'm quite sure I've left something
out
of my code (below)

Private Sub cboPartNo_NotInList(NewData As String, Response As Integer)
Dim strMsg As String
Dim ctl As Control
Set ctl = Screen.ActiveControl

strMsg = "The Part Number you entered, " & NewData & ", is not in the Part
Number List!" & _
vbCrLf & "Do you want to add it?"
If MsgBox(strMsg, vbYesNo, "Not listed") = vbYes Then

DoCmd.OpenForm "frm_PartNumbers"
Else
ctl.Undo
Response = acDataErrContinue
End If
End Sub

The code works just fine with the exception that when the form opens up
for
entering the new part number information, an Access Message Box pops up
and
indicates that the number entered in the combo box is not in the Part No
List, and wants the user to pick from the list. How do I keep this
message
box from opening?


You need to make the code wait until after the user has added the new part
number via the form, and then you need to tell Access that the user has done
so. Change your code like this:

If MsgBox(strMsg, vbYesNo, "Not listed") = vbYes Then
DoCmd.OpenForm "frm_PartNumbers", WindowMode:=acDialog
Response = acDataErrAdded
Else
ctl.Undo
Response = acDataErrContinue
End If
 
D

Deb

Many thanks, Dirk -- worked like a champ!

Dirk Goldgar said:
You need to make the code wait until after the user has added the new part
number via the form, and then you need to tell Access that the user has done
so. Change your code like this:

If MsgBox(strMsg, vbYesNo, "Not listed") = vbYes Then
DoCmd.OpenForm "frm_PartNumbers", WindowMode:=acDialog
Response = acDataErrAdded
Else
ctl.Undo
Response = acDataErrContinue
End If


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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