3 Replies - 1230 Views - Last Post: 28 March 2013 - 10:33 PM Rate Topic: -----

#1 mrkey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-March 13

Runtime Error 424 "Object Required"

Posted 27 March 2013 - 09:41 PM

Hi I am having problem with this.

here's my connection code:

 
Public DBCon As ADODB.Connection
Public Concom As ADODB.Command
Public DBrs As ADODB.Recordset

Public Sub DBConnect()

    Set DBCon = New ADODB.Connection
    Set Concom = New ADODB.Command
    Set DBrs = New ADODB.Recordset
    
    DBCon.ConnectionString = "Provider=Microsoft.jet.oledb.4.0; Data Source=" & App.Path & "\Database\HRIS.mdb"
    DBCon.Open
    Concom.ActiveConnection = DBCon
End Sub

Public Sub SQLcmd(SQLstatement As String)
    Concom.CommandText = SQLstatement
    Set DBrs = Concom.Execute
End Sub



and here's the line that is giving me an error:

'On Error GoTo here:
        
    SQLcmd "select max(EmpID) from tblEmpPerInfo"
    [b]txtEmpID.Text = rs.Fields(0) + 1[/b] <-- this one here.
    'Exit Sub
    
'here:
    'If Err.Number Then                     <-- this is only if there is no record on the database yet.
    '    txtEmpID.Text = "1001"
    '    Exit Sub
    'End If



what I'm trying to do is get the max id number in the database and add 1 on it to be use for the next record.

Is This A Good Question/Topic? 0
  • +

Replies To: Runtime Error 424 "Object Required"

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,769
  • Joined: 26-March 09

Re: Runtime Error 424 "Object Required"

Posted 28 March 2013 - 01:12 AM

You seem to be missing a chunk of code there....you refer to recordset rs, but I don't see where you're getting that from, which might explain the error. You need to show us the complete code related to where you create the connection and execute the query.

In regards to getting the Max + 1, you could probably do that in the query itself, with something like
 select max(field)+1 from table

This post has been edited by maj3091: 28 March 2013 - 01:17 AM

Was This Post Helpful? 1
  • +
  • -

#3 mrkey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-March 13

Re: Runtime Error 424 "Object Required"

Posted 28 March 2013 - 05:09 AM

View Postmaj3091, on 28 March 2013 - 01:12 AM, said:

In regards to getting the Max + 1, you could probably do that in the query itself, with something like
 select max(field)+1 from table


thanks for this.. yeah there is something wrong with the "rs" thingy wherein it should be BDrs as decleared above.. thank you very much..
Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Runtime Error 424 "Object Required"

Posted 28 March 2013 - 10:33 PM

The SQL to get the highest ID number would be
SELECT TOP 1 ID from myTable ORDER BY ID DESC
So you sort by ID in descending order and then take the top value from the table. And in SQL you explain that backwards. :)

This post has been edited by BobRodes: 28 March 2013 - 10:34 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1