Im trying to get a 2 digit number from my database. Database is Clients then Table is Contracts. Im new to db and ive compiled this code with other parts of code that works in my program but isnt working now.
Basically i put label1 = RevServiceDay(txtAcctID) it it pulls the account number from a text box and needs to look up the service date for this client. When i check it the recordcount shows as "-1" so im assuming there is no records found. But i am looking in my database and it does have information in it. Ive altered the code many times trying to get it to work and i feel this is the closest way but i just cant seem to get it. Any help would be appreciated!! Thanks!
Running in circles is what I do best!
Code:
Public Function RevServiceDay(sdCustomer)
Dim mCn As ADODB.Connection
Dim mRs As ADODB.Recordset
Dim Rs As ADODB.Recordset
Dim sSql As String
Set mCn = New ADODB.Connection
Set mRs = New ADODB.Recordset
mCn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\my work\Programs\clients.mdb"
mRs.Open "Contracts", mCn, adOpenKeyset, adLockOptimistic, adCmdTable
sSql = "SELECT ServiceDay FROM Contracts WHERE CustomerID LIKE '%" & Format(sdCustomer, "00000000") & "%'"
Set Rs = New ADODB.Recordset
Rs.Open sSql, mCn, adOpenForwardOnly, adLockReadOnly
While Not Rs.EOF And Not Rs.BOF
testStr = GetString(Rs.Fields("ServiceDay").Value)
Rs.MoveNext
Wend
RevServiceDay = testStr
Rs.Close
mRs.Close
mCn.Close
End Function
Basically i put label1 = RevServiceDay(txtAcctID) it it pulls the account number from a text box and needs to look up the service date for this client. When i check it the recordcount shows as "-1" so im assuming there is no records found. But i am looking in my database and it does have information in it. Ive altered the code many times trying to get it to work and i feel this is the closest way but i just cant seem to get it. Any help would be appreciated!! Thanks!
Running in circles is what I do best!