Results 1 to 4 of 4
  1. #1
    ItsJustMe3377 is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Oct 2017
    Posts
    4

    Error message when trying to run vba code using cmd button in form


    I created a button on a form. The purpose is to Send and email with an attachment from Excel. I am getting an error message, but can't find the error. Can someone help? Note: Email_List is a query.
    Error Message: The expression On Click you entered as the event property setting produced the following err: Procedure declaration does not match description of event or procedure having the same name.


    [Private Sub cmd3_Click()

    Dim myRs As DAO.Recordset
    Set myRs = CurrentDb().OpenRecordset("Email_List")


    If myRs.RecordCount > 0 Then
    myRs.MoveFirst

    While Not myRs.EOF
    Call sendEmail(myRs![Email_Distribution_List], "FYI: " & myRs![Email_Subject], "some text.", False, myRs![Final_File_Name])
    myRs.MoveNext
    Wend
    End If
    myRs.Close
    Set myRs = Nothing


    End Sub]

    Thank you!!!

  2. #2
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    If you really have the leading and ending square brackets, I would say that's the problem. If not, the message is telling you that the name of the control you're clicking on to run this event doesn't match the name as it is defined in the procedure - cmd3_Click. Perhaps you changed the name of the control.

    Such names are not much help in identifying what's what down the road. You should adopt a naming convention. Welcome to the forum by the way. If you would be so kind, please use code tags for anything more than a few lines. It's the # on the message toolbar.
    Thanks.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    ItsJustMe3377 is offline Novice
    Windows 7 32bit Access 2013 32bit
    Join Date
    Oct 2017
    Posts
    4
    My apologies. I am new to forums. The [] at the beginning and at the end where to what I thought was tagging the code.

  4. #4
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    No apologies necessary. Let us know if you don't find that the name of the control is out of sync with the event name;
    or now that I paid more attention to the code, it may be your use of parentheses with CurrentDb. It should be CurrentDb.OpenRecordset
    Another tip: in future, indicate which line of code produces the error message, and if applicable, which part is highlighted. Thinking now that I would have not made the supposition that the error occurred when you clicked on the control if you had done that. Would have told me that the code did run, thus I wouldn't have wasted your time with that guess. Again, no problem - just providing tips.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. VBA code for form to display Error message
    By CTVT in forum Programming
    Replies: 9
    Last Post: 12-11-2015, 09:53 PM
  2. Replies: 5
    Last Post: 07-30-2014, 03:55 PM
  3. Replies: 2
    Last Post: 03-28-2014, 07:30 AM
  4. Error message code
    By FJM in forum Access
    Replies: 11
    Last Post: 09-09-2013, 04:42 AM
  5. Replies: 3
    Last Post: 07-13-2011, 02:04 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