NotInList code

I

Ivor Williams

I'm trying to use the following code to add a new part using a form called
frmNewPart. What I want to have happen is this:

I enter a new part number in a combo box in which the Limit to List
property is set to Yes

The NotInList event causes the frmNewPart form to open

The information for the new part is entered on the frmNewPart form

Then new part is added to the tblParts table from which the
frmNewPart form gets its data

The frmNewPart form closes and the combo box is populated with data
for the newly added part





Private Sub PartNo_NotInList(NewData As String, Response As Integer)

Dim stDocName As String

Dim stLinkCriteria As String



stDocName = "frmNewPart"

DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog

Response = acDataErrAdded

End Sub



The frmNewPart form doesn't open. I'm not sure why, I think it may have to
do with stLinkCriteria. Please help.



Ivor
 
T

tina

well, you're not setting any value for stLinkCriteria, so just remove it.
and btw, you don't really need to set a variable for the form name, either.
try

Private Sub PartNo_NotInList(NewData As String, Response As Integer)

DoCmd.OpenForm "frmNewPart", , , , , acDialog
Response = acDataErrAdded

End Sub

suggest you first confirm that the user wants to add the part number to the
list; after all, the user may have simply made a typo. to verify the user's
intent, try

Private Sub PartNo_NotInList(NewData As String, Response As Integer)

If Msgbox("Do you want to add part number " & """" & NewData _
& """" & " to the list?", vbYesNo, "Update the list?") = vbYes
DoCmd.OpenForm "frmNewPart", , , , , acDialog
Response = acDataErrAdded
Else
Response = acDataErrContinue
Me!PartNo.Undo
Me!PartNo.Dropdown
End If

End Sub

hth
 

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