Results 1 to 6 of 6

Thread: [RESOLVED] error 3265

  1. #1

    Thread Starter
    Member kirara22's Avatar
    Join Date
    Feb 2009
    Posts
    54

    Resolved [RESOLVED] error 3265

    how to generate automatic IDnumber of customer?


    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

    tnx
    Last edited by kirara22; Mar 16th, 2009 at 04:44 AM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  3. #3

    Thread Starter
    Member kirara22's Avatar
    Join Date
    Feb 2009
    Posts
    54

    Re: error 3265

    i c.. hehhehe..

    can u help me out how would i generate automatic id number for customer?

    tnx

  4. #4
    Hyperactive Member
    Join Date
    May 2006
    Posts
    365

    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

  5. #5

    Thread Starter
    Member kirara22's Avatar
    Join Date
    Feb 2009
    Posts
    54

    Re: error 3265

    but how would it apper during loadform in my IDNUMBER.caption.

    tnx

  6. #6
    Hyperactive Member
    Join Date
    May 2006
    Posts
    365

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width