I am trying to build an ADODB recordset.
Here is my code
Set Recordset = New ADODB.Recordset
With Recordset
.ActiveConnection = CurrentProject.Connection
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "Select * From tblContact Where tblContact.FirstName = " & Chr(34) & Me!txtFirstName & Chr(34) & " AND tblContact.LastName = " & Chr(34) & Me!txtLastName & Chr(34) & " AND tblContact.MiddleInitial = " & Chr(34) & Me!txtMiddleInitial & Chr(34) & ";"
End With
Now the txtfields on the form require a value for First Name and Last Name
But Not for Middle Initial
(this is handle in the form code)
So when this code is run to build a recordset the value for txtMiddleInitial MIGHT be null.
If it isnt...the code works fine.
For example
If I have a record in the contact table whose first name is Joe
Last name is Somebody
and Middle initial is Q
and the txt fields were filled out with those values it would successfully return the record.
BUT if I have a record for Joe Sombody with NO middle initial value and the txtMiddleInitial field is empty...
That Should return the correct record.
Instead it returns an EOF which is NOT the case.
Any ideas why this isnt working.
I am stumped.
Here is my code
Set Recordset = New ADODB.Recordset
With Recordset
.ActiveConnection = CurrentProject.Connection
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "Select * From tblContact Where tblContact.FirstName = " & Chr(34) & Me!txtFirstName & Chr(34) & " AND tblContact.LastName = " & Chr(34) & Me!txtLastName & Chr(34) & " AND tblContact.MiddleInitial = " & Chr(34) & Me!txtMiddleInitial & Chr(34) & ";"
End With
Now the txtfields on the form require a value for First Name and Last Name
But Not for Middle Initial
(this is handle in the form code)
So when this code is run to build a recordset the value for txtMiddleInitial MIGHT be null.
If it isnt...the code works fine.
For example
If I have a record in the contact table whose first name is Joe
Last name is Somebody
and Middle initial is Q
and the txt fields were filled out with those values it would successfully return the record.
BUT if I have a record for Joe Sombody with NO middle initial value and the txtMiddleInitial field is empty...
That Should return the correct record.
Instead it returns an EOF which is NOT the case.
Any ideas why this isnt working.
I am stumped.