I tried but I am still doing something wrong. The limit to list is set to
YES, so I do get the standard error message when I try to enter data, but it
is as if this code does not exist.
This is what I have, and I am pasting it into the code module of visual
basic in the "not in list event" procedure. Still not firing.
Private Sub cboMainGuestLastName_NotInList(NewData As String, Response As
Integer)
Dim rst As Recordset
If MsgBox(NewData & " Is Not In MainGuestInfo " & vbNewLine _
& "Do you want to add it", _
vbInformation + vbYesNo, "Not Found") = vbYes Then
CurrentDb.Execute ("INSERT INTO MainGuestInfo (MainGuestLastName) " _
& "VALUES ('" & NewData & "');"), dbFailOnError
Me.Requery
Set rst = Me.RecordsetClone
rst.FindFirst "[MainGuestLastName] = '" & NewData & "'" And
MainGuestFirstName Is Null
Me.Bookmark = rst.Bookmark
Set rst = Nothing
Me.txtMainGuestGender.SetFocus
Response = acDataErrAdded
Else
Me.cboMainGuestLastName.Undo
Response = acDataErrContinue
End If
End Sub
I am sooo newbie at this I can't even believe that I can actually write this
message!
Klatuu said:
Change this line:
CurrentDb.Execute ("INSERT INTO CISAttributeTable (ACTIVITY) "
To:
CurrentDb.Execute ("INSERT INTO MainGuestInfoTable (MainGuestLastName)
"
And this line:
rst.FindFirst "[Activity] = '" & NewData & "'"
To:
rst.FindFirst "[MainGuestLastName)] = '" & NewData & "'"
And This needs to be change from cboActivity to the name of your combo box:
Me.cboActivity.Undo
and txtDescription needs to be eiter omitted or you can change
txtDescription to the control you want to have the focus after the new record
has been added.
Me.txtDescription.SetFocus
The problem here is that if you have thousands of records, it is almost a
certainty you will have multiple last names. The FindFirst may not retrieve
the record you just created. You may have to add an additional qualifer to
get the correct record. Without knowing enough about your data, my first
guess is you have a MainGuestClientFirstName. Since your existing records
probably have a first name filled in and the new one doesn't, you may need
something like this in your FindFirst:
rst.FindFirst "[MainGuestLastName)] = '" & NewData & "' AND
MainGuestFirstName IS NULL"
:
Thank you so much for your responses, but I am afraid I need even more hand
holding. Can I get a very specific instruction as to what to do if:
The form is called MainGuestInfo. The table is MainGuestInfoTable and it
holds ALL my client data. (Is this OK, or should I have another table or
query that will only hold the last names?) The combo field is
MainGuestLastName which is NOT the primary key. The property limit to list
IS set to YES.
Is the only thing that I have to replace in the code that you have given me
is the word ACTIVITY for MainGuestLastName? Other than than I just cut and
paste what you sent?
All help is appreciated. What I am doing now is if I think I recognize a
name, I do a search, lots of error potential considering that I have
thousands of clients. (but I am only on number 356 in terms of entering the
data!)
Thanks so much!!!
:
Here is an example from one of my apps. Note that to use the Not In List
event, the Limit To List property for the combo must be set to Yes. In the
example below, if the user clicks yes on the message box, a new record is
created with just the primary key value and the record source is positioned
on the new record ready for data entry.
Private Sub cboActivity_NotInList(NewData As String, Response As Integer)
Dim rst As Recordset
If MsgBox(NewData & " Is Not In The Attribute Table " & vbNewLine _
& "Do you want to add it", _
vbInformation + vbYesNo, "Not Found") = vbYes Then
CurrentDb.Execute ("INSERT INTO CISAttributeTable (ACTIVITY) " _
& "VALUES ('" & NewData & "');"), dbFailOnError
Me.Requery
Set rst = Me.RecordsetClone
rst.FindFirst "[Activity] = '" & NewData & "'"
Me.Bookmark = rst.Bookmark
Set rst = Nothing
Me.txtDescription.SetFocus
Response = acDataErrAdded
Else
Me.cboActivity.Undo
Response = acDataErrContinue
End If
End Sub
:
Greetings from the backpackers hostel in Panama.
I have gotten for the most part my forms and tables OK, and now I am just
suffering with unnecessary repetition of data entry which will be the subject
of further posts, I am sure.
For now, can someone walk me through in a detailed fashion, how to do a "not
in list" event so I can simply enter a new guest name, and if it does not
appear in my existing list of guests, allow me to enter the new client?
I don't even really understand who to add an event in the first place!