G
Guest
Access 2003.
I have a form with a simple dropdown, bound to a lookup table. The table
contains a primary key, a date field, and a text field. The dropdown is only
bound to the date and text fields. Limit to List=No, so I can let the user
type in a new date and automatically add it to the lookup table for later
use.
Problem: When the code searches for the date in the recordset, it never
finds it, even if the date is already in the lookup table!
Here is my code. What the heck am I doing wrong? It must be obvious, since
I'm stuck.
Private Sub cboLibDate_AfterUpdate()
' If a new date is entered, update the tblLibraryDinner table
' The combo box is requiried to display the new event date.
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim LibPlace As String ' where a new lib dinner held
Dim TheDate As Date
TheDate = Me.cboLibDate.Text
Set db = CurrentDb
Set rs = db.OpenRecordset("tblLibraryDinner", dbOpenDynaset)
rs.MoveLast
rs.MoveFirst
rs.FindFirst "[DateOfDinner] = " & TheDate
If rs.NoMatch Then
' the date is not there, so add it.
LibPlace = InputBox("New event! Enter location of dinner", _
"New dinner date: " & Me.cboLibDate)
With rs
.AddNew
!DateOfDinner = Me.cboLibDate
!Location = LibPlace
.Update
End With
Me.cboLibDate.Requery
End If
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub
Thanks for any help. - George
I have a form with a simple dropdown, bound to a lookup table. The table
contains a primary key, a date field, and a text field. The dropdown is only
bound to the date and text fields. Limit to List=No, so I can let the user
type in a new date and automatically add it to the lookup table for later
use.
Problem: When the code searches for the date in the recordset, it never
finds it, even if the date is already in the lookup table!
Here is my code. What the heck am I doing wrong? It must be obvious, since
I'm stuck.
Private Sub cboLibDate_AfterUpdate()
' If a new date is entered, update the tblLibraryDinner table
' The combo box is requiried to display the new event date.
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim LibPlace As String ' where a new lib dinner held
Dim TheDate As Date
TheDate = Me.cboLibDate.Text
Set db = CurrentDb
Set rs = db.OpenRecordset("tblLibraryDinner", dbOpenDynaset)
rs.MoveLast
rs.MoveFirst
rs.FindFirst "[DateOfDinner] = " & TheDate
If rs.NoMatch Then
' the date is not there, so add it.
LibPlace = InputBox("New event! Enter location of dinner", _
"New dinner date: " & Me.cboLibDate)
With rs
.AddNew
!DateOfDinner = Me.cboLibDate
!Location = LibPlace
.Update
End With
Me.cboLibDate.Requery
End If
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub
Thanks for any help. - George