-
[RESOLVED] error 3265
how to generate automatic IDnumber of customer?
:confused: :confused: :confused:
i try the following code:
Code:
Const DBPATH = "dataBASE.mdb"
Dim cn As New ADODB.Connection, rs As New ADODB.Recordset
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBPATH
SQL = "SELECT MAX(IDNUMBER) FROM table1"
newID_Number.caption = rs.Fields("LAST_ID_nuMBER") + 1
End Sub
i've got he following error mesage.
item cannot be found in the collection corresponding to the requested name or ordinal.
sorry im really new vb:o
tnx:)
-
Re: error 3265
That is not a VB error. That is an SQL error. It means that the field you are referencing doesn't exist.
-
Re: error 3265
i c.. hehhehe..
can u help me out how would i generate automatic id number for customer?
tnx :)
-
Re: error 3265
Hello,
If the database uses an autonumber field for the table primary key then you do not need to create the key field value yourself, the database will do it automatically.
Kind regards
Steve
-
Re: error 3265
but how would it apper during loadform in my IDNUMBER.caption.
tnx
-
Re: error 3265
Hello,
From post #2 Hack identified that you were using an incorrect field name for the primary key field. If that is the case you will need to correctly identify the name of the primary key field and then use its value for the label caption.
You will need to use the recordset object:
Code:
With rs
.ActiveConnection = cn
.Source = SQL
.Open
End With
newID_Number.caption = rs(0).Value
When you need to create a new record the rs.AddNew will automatically cause a new identity key field value to be created.
rs.Update will then write the new values to the database.
I will add that the user doesn't need the key field value and doesn't even need to know it exists.
P.S. This code is written off the top of my head so may contain errors.
Kind regards
Steve