RE: Forms are fun (except when they need combo box VBA code I don'
- From: Klatuu <Klatuu@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 9 Jun 2006 13:06:01 -0700
It can't find it because the form's recordset has to be required. You put it
in the table, but it is not in the recordset. A form's recordset only
contains the records that were in the table when the form was loaded or last
requried.
Private Sub AgentName_NotInList(NewData As String, Response As Integer)
Dim db As Database
Dim rs As Object
Set db = CurrentDb
'Add the new value to the field
db.Execute "INSERT INTO TotalAgentListABCD (LastName) VALUES (""" & NewData
& """)", dbFailOnError
'Tell Access you've added the value
Response = acDataErrAdded
Me.Requery
rs.FindFirst "[LastName] = '" & Me![AgentName] & "'"
db.Close
Set db = Nothing
"Gnowor" wrote:
Good news bad news situation here..
Got the NotInList event to add a record to the table (I had the table name
wrong), problem is, that after the record's added, I get an error that it
can't find the record. What I think is happening is that it's loading the
list for the combo box when I open the form, but I need it to reload that
list when the new record is added, and then repeat the find I have in my
AfterUpdate Sub to select the new record it just added. Again, I think I'm
starting to get a grasp of what i need to do, the code is just eluding me at
the moment. I'm also probably adding way mroe steps than neccessary.
BTW, Klatuu you are frigging awesome for helping me through this. If you're
ever in the San Fran Bay Area, I owe you big for all the help. AIM=gnowor if
you've got the time.
-------------
Private Sub AgentName_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[LastName] = '" & Me![AgentName] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
Private Sub AgentName_NotInList(NewData As String, Response As Integer)
Dim db As Database
Dim rs As Object
Set db = CurrentDb
'Add the new value to the field
db.Execute "INSERT INTO TotalAgentListABCD (LastName) VALUES (""" & NewData
& """)", dbFailOnError
'Tell Access you've added the value
Response = acDataErrAdded
rs.FindFirst "[LastName] = '" & Me![AgentName] & "'"
db.Close
Set db = Nothing
End Sub
- Prev by Date: Re: Email Address Validation
- Next by Date: Re: loop through rows on a continuos form
- Previous by thread: Re: Form is editable even after setting it to false
- Next by thread: Re: Connect to text file using ADO?
- Index(es):
Relevant Pages
|