Results 1 to 2 of 2
  1. #1
    sgp667 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    17

    Object Required Error

    Can someone tell me why do I get "Object required" error for this?


    VBA highlights "Employees ="


    Private Sub NewPayButton_Click()


    Dim PayrollApp As Database
    Dim Hours As Recordset
    Dim Employees As Integer




    Set PayrollApp = CurrentDb
    Set Hours = PayrollApp.OpenRecordset("Hours")
    Set Employees = DCount("[ID]", "Employees", "[Status] = 'Working'")


    NewHours:
    Hours.AddNew
    Hours.Update
    Set Employees = Employees - 1
    If Employees > 1 Then GoTo NewHours


    End Sub

  2. #2
    SteveH2508 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2010
    Location
    Chelsea, London, England
    Posts
    117
    Remove the Set keyword from Set Employees = DCount("[ID]", "Employees", "[Status] = 'Working'") and from Set Employees = Employees - 1
    - you are dealing with an ordinary variable not an object.

    Your code

    Hours.AddNew
    Hours.Update

    is not writing in any values into the new record.

    Also you should disambiguate your DAO declarations

    Dim PayrollApp As DAO.Database
    Dim Hours As DAO.Recordset

    I would not name a variable the same as a field name (Employees) - there is much scope for confusion on both your part and Access/VBA.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Object Required When Importing
    By barks1981 in forum Import/Export Data
    Replies: 4
    Last Post: 07-05-2011, 01:21 AM
  2. Error: Object Required
    By compooper in forum Programming
    Replies: 6
    Last Post: 06-22-2011, 07:52 AM
  3. Object Required Error.
    By Robeen in forum Forms
    Replies: 1
    Last Post: 03-28-2011, 10:30 AM
  4. Run-time error '424': Object required
    By cowboy in forum Programming
    Replies: 18
    Last Post: 07-07-2010, 03:32 PM
  5. Object required
    By duckie10 in forum Access
    Replies: 1
    Last Post: 05-15-2009, 02:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums