I have an Access database that has the following table defined:
Datex Date/Time (with the format set at Short Date 5/5/2014)
Timex Date/Time (with the format set at Short Time 17:35)
Contact Text (field size 50)
Reference Text (field size 50)
Type Text (field size 50)
The tables looks like this ...
1 5/5/2014 12:00 Doe, John SharePoint Note This is a note
2 5/16/2014 13:50 Slick, Mary SQL Note This is a note also.
How do I code in VBA a select statement that will read a specific record? I know the Date, Time and Contact. Any help will be appreciated.
Const c_SQL As String = "SELECT * FROM TableName " & _
"WHERE Datex = #@D# AND Timex = #@T# AND Contact = '@C';"
Dim rst As DAO.Recordset
Dim strSQL As string
strSQL = Replace(Replace(Replace(c_SQL, "@D", Format(SomeDate, "yyyy-mm-dd"), & _
"@T", Format(SomeTime, "hh:nn"), & _
Set rst = Currentdb.OpenRecordset(strSQL, dbOpenSnapshot)
If rst.EOF = True Then
' --> no record found.
' You can retrieve the data in rst!NotesID, rst!Datex, etc.
Set rst = Nothing
Where SomeDate, SomeTime and SomeContact are the known values for the row you're looking for.