Trouble with my NotOnList code

G

Gordon

The code below works but it involves me having to type the new
"OnNotinList" entry twice - first in the combo box on the main form,
then on the data entry form that pops up when I say yes to adding a
new entry.

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

' Add a new entry by typing a name in the box.

Dim intNewEntry As Integer, strTitle As String, intMsgDialog As
Integer

' Display message box asking if user wants to add a new Sculpture.
strTitle = "Entry Not In List"
intMsgDialog = vbYesNo + vbQuestion + vbDefaultButton1
intNewEntry = MsgBox("Do you want to add a new entry?",
intMsgDialog, strTitle)

If intNewEntry = vbYes Then
' Remove new name from ID combo box so
' control can be requeried when user returns to form.
DoCmd.RunCommand acCmdUndo

' Open AddSculpture form.
DoCmd.OpenForm "frmMedium", acNormal, , , acAdd, acDialog,
NewData

' Continue without displaying default error message.
Response = acDataErrAdded
End If
End Sub

I expected the "Newdata" string to carry the value forward and
therefore have to type it only once. Have I missed something?

Gordon
 
D

Douglas J. Steele

It does carry forward: it just doesn't do it automatically.

You're passing the value of NewData as the form's OpenArgs parameter. In the
Load event of frmMedium, put code to check whether or not Me.OpenArgs is not
null. If it isn't Null, use Me.OpenArgs to populate the appropriate field on
your form:

Private Sub Form_Load()

If IsNull(Me.OpenArgs) = False Then
Me.SomeField = Me.OpenArgs
End If

End Sub
 

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