The seek command is not identifying my autoNumber

iamraja5

Registered User.
Local time
Today, 12:51
Joined
Jun 2, 2006
Messages
11
Hi all
I have table called "Customer Data" and it has a field called AccountNumber.This field is a Auto/Number type. Life is normal at this point.

Now I have a form with text boxes, user enters a value in text box. ( which is a accountnumber). Upon entring a account number I have the following codes which look for the account number, if account number is found then it displays customer details.
I have a acount number = 22 in the customer data table, but if enter this number my code is not returing any data. it says " Customer Not found".

Please help. Not sure why it is not seeking my account number.

Private Sub accountNumber_Exit(Cancel As Integer)
Dim res As String
Dim acnumber As Integer
Dim abc As dao.Recordset
Set abc = CurrentDb.OpenRecordset("Customer Data")
abc.Index = "PRIMARYKEY"
If IsNull(Me.accountNumber) Then
MsgBox " Account number has to be entered"
Else

acnumber = CStr(Me.accountNumber) // I tried just using acnumber, converting, etc//
abc.Seek "=", acnumber
If abc.NoMatch Then
MsgBox "Customer not found"
Else
Me.lname = abc.Fields("Customer_Last_Name")
Me.add1 = abc.Fields("Cus_Address_1")
Me.add2 = abc.Fields("Cus_Address_2")
Me.phone = abc.Fields("Cus_Tel_No")

End If
End If
End Sub
 
autonumber should not be used as data entry fields.
autonumber implies it numbers automatically, you can't enter it in.
suggest you use another field for you customer number.
lightray
 
1. begore you can use seek you have to set a key to seacrh on. the key names are the keys displayed in your table. in this case its probably something like rst.index = "primarykey" (maybe wrong sysntax) - only then can you use seek,

2. also seek won't work an a linked table - you have to use find etc. Have you split the database.

Definitely don't convert to a string though - autonumber is a long number, and can be searched as any other number.
 

Users who are viewing this thread

Back
Top Bottom