Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jun 2001
    Posts
    146
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DAO problem (2000 SR-1)

    Hi,

    I'm trying to get some code to run but having no luck. Here is the procedure:

    Private Function Calculate_Bonus_for_All_Current_Records_Click()

    Dim rs As DAO.Recordset
    Dim db As DAO.DATABASE

    Set db = CurrentDb
    Set rs = CurrentDb.OpenRecordset("BonusTemp")

    rs.MoveFirst

    Do While Not rs.EOF

    Call CalculateBonus_Click
    rs.MoveNext

    Loop

    rs.Close

    End Function

    The called procedure is defined as Public Function CalculateBonus_Click().

    When I test the calling procedure from within the IDE, it just opens a Macros dialog box. When I test the calling procedure from the form button, I get an error message saying that "Procedure declaration does not match description of event of procedure having the same name." I'm not sure what's going on there since the Click event of the button says "[Event Procedure]" and the form button is titled Calculate_Bonus_for_All_Current_Records.

    I tried adding the Microsoft DAO 3.6 Object library through Tools > References, but that hasn't made a difference.

    Thanks,
    Bob

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: DAO problem (2000 SR-1)

    Event procedures are Subs not functions. That may be the problem.
    Charlotte

  3. #3
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: DAO problem (2000 SR-1)

    If the procedure Calculate_Bonus_for_All_Current_Records_Click() is an event procedure, it must be declared as a Sub, not Function. You can't define an event procedure as a function! Also, you cannot test a procedure in a class module (including form modules) in IDE by clicking Run Sub button or entering F5. As noted this will only open VBE "Macros" dialog. The class object name must be provided. To run a form's event procedure from IDE, enter something like this in Immediate window:

    Form_frmListFiles.SelectAll_btn_Click

    Note that if form not already open, running the command above will open form then execute the procedure (SelectAll_btn_Click, a command button Click procedure). Note also you must refer to form not by its name, but by the name under which it is listed in VBE Project Explorer "MS Access Class Objects" list, with the "Form_" prepended to form name. Also, this:

    Set db = CurrentDb
    Set rs = CurrentDb.OpenRecordset("BonusTemp")

    should be changed to:

    Set db = CurrentDb
    Set rs = db.OpenRecordset("BonusTemp")

    I'd recommend using database object variable to open recordset, using CurrentDB directly may cause odd errors.

    HTH

Posting Permissions

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