Query = "select * from table2 where number='" + Text5.Text + "'"
Rs.Open (Query), Conn, adOpenStatic, adLockReadOnly

Hi,
If "number" is defined as Auto number in Access database, second line generates an error. If "number" is not defined as Auto number then, no problem. What can i do?
Thanks

try the following code :-

take two labels(label1 and label2) and a textbox(Text1)
here the database ->"aa.mdb"
table ->"aa"
fields ->"id" (long,autonumber) ; "name" (text)

Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim str As String

str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\aa.mdb;Persist Security Info=False"
conn.ConnectionString = str
conn.Open

str = "select * from aa where id = " & Val(Text1.Text)
rs.Open str, conn, adOpenStatic, adLockReadOnly
If rs.RecordCount > 0 Then
    Label1.Caption = rs!id
    Label2.Caption = rs!Name
Else
    MsgBox "No record found."
End If
Text1.Text = ""
Text1.SetFocus
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.