Results 1 to 14 of 14
  1. #1
    dccjr's Avatar
    dccjr is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    Colorado Springs, CO
    Posts
    138

    Command Button Problem


    I am getting the following error when I click on a command button on my Home screen:

    "The expression On Click you entered as the event property setting produced the following error: Procedure declaration does not match description of event or procedure having the same name."

    Here is the event procedure:

    Code:
    Private Sub cmdDataEnter_Click()
        Application.DisplayAlerts = False
        ActiveWindow.Close
        Application.DisplayAlerts = True
        DoCmd.OpenForm "frmDataForm", acNormal, "", "", , acNormal
    End Sub
    I recreated the procedure yesterday, and it worked. Today it is doing the same thing that it was before. I have double checked the command button name and form names. Everything seems to be correct. I even tried using the DoCmd alternative to this (below), but it didn't help.

    Code:
    Private Sub cmdDataEnter_Click()
        DoCmd.Close acForm, "frmHome", acSaveNo
        DoCmd.OpenForm "frmDataForm", acNormal, "", "", , acNormal
    End Sub
    What am I missing?

  2. #2
    JBMoorpark is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    5
    I'm not sure why you have the acNormal in the last position. That is normally the location of the arguments you are passing to the form. Is there a reason for that?

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Yep, you have added too much. You don't need the empty strings and the "acNormal" is in the wrong place.
    The syntax should be:
    Code:
    DoCmd.Close acForm, "frmHome"
    DoCmd.OpenForm "frmDataForm", acNormal


    "acSaveNo" is only effective if you have used code to change the design of the form. If you want to ensure the DATA changes are saved before the form is closed, use the "Dirty" property.
    Code:
    If Me.Dirty Then
      Me.Dirty = False
    End If
    
    DoCmd.Close acForm, "frmHome"
    DoCmd.OpenForm "frmDataForm", acNormal

  4. #4
    dccjr's Avatar
    dccjr is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    Colorado Springs, CO
    Posts
    138
    I changed the syntax, but am getting the same error. Can anyone think of anything else that might be causing this?

  5. #5
    JBMoorpark is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    5
    Quote Originally Posted by dccjr View Post
    I changed the syntax, but am getting the same error. Can anyone think of anything else that might be causing this?

    What form is this code located in? frmHome?

    Also, what happens if you simply open frmDataForm from the Navigation Pane? Do you get the same error?

  6. #6
    dccjr's Avatar
    dccjr is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    Colorado Springs, CO
    Posts
    138
    The code in in frmHome. I can open any form in the Navagation pane with no problem. I have a couple of company logo images on frmHome that have DblClick event to take the user to various company webpages. These were working previously, but now generate the same error.

  7. #7
    JBMoorpark is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    5
    Quote Originally Posted by dccjr View Post
    The code in in frmHome. I can open any form in the Navagation pane with no problem. I have a couple of company logo images on frmHome that have DblClick event to take the user to various company webpages. These were working previously, but now generate the same error.
    I don't see anything in the code that you posted that would cause that error. Also, if you are getting similar errors when clicking on the logos it sounds like the coding error is somewhere else, such as the general declarations.

    I think you'd need to show us the entire code for the form to really make much sense out of it.

  8. #8
    dccjr's Avatar
    dccjr is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2012
    Location
    Colorado Springs, CO
    Posts
    138
    Here is the complete code on frmHome. Do the General Declarations (ie., Option Explicit, Compare Database) on other forms effect this one?

    Code:
    Option Explicit
    Private Sub cmdDataEnter_Click()
        DoCmd.Close acForm, "frmHome"
        DoCmd.OpenForm "frmDataForm", acNormal
    End Sub
    Private Sub cmdExit_Click()
        CurrentDatabase.Close
    End Sub
    Private Sub cmdReportsCharts_Click()
        DoCmd.Close acForm, "frmHome"
        DoCmd.OpenForm "frmReportsCharts", acNormal
    End Sub
    Private Sub cmdSearch_Click()
        DoCmd.Close acForm, "frmHome"
        DoCmd.OpenForm "frmSearch", acNormal
    End Sub
    Private Sub imgACE_DblClick(Cancel As Integer)
        ACESite
    End Sub
    Private Sub imgGoodrich_DblClick(Cancel As Integer)
        GoodrichSite
    End Sub
    Private Sub imgRootCause_DblClick(Cancel As Integer)
        RootCauseSite
    End Sub
    Private Sub imgUTC_DblClick(Cancel As Integer)
        UTCSite
    End Sub
    Private Sub cmdAdmin_DblClick()
    Dim strIDAdmin As String
       Dim frmCurrentForm As Form
       If Environ("USERNAME") <> "david.cromer" Then
            msgbox ("You do not currently have administrator rights for this database. Please contact David Cromer, Dept. 549, for questions.")
       Else
            Set frmCurrentForm = Screen.ActiveForm
            DoCmd.Close acForm, "frmCurrentForm", acSaveNo
            DoCmd.OpenForm "frmAdminTools", acNormal, "", "", , acNormal
       End If
    End Sub
    I am at a complete loss. Thanks for the continued assistance.
    Last edited by dccjr; 01-21-2013 at 06:05 PM. Reason: typo

  9. #9
    JBMoorpark is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    5

    What has changed

    Quote Originally Posted by dccjr View Post
    Here is the complete code on frmHome. Do the General Declarations (ie., Option Explicit, Compare Database) on other forms effect this one?


    I am at a complete loss. Thanks for the continued assistance.

    No, the General Declarations on other forms are only evaluated when that form is opened. It doesn't affect this current form.

    How are ACESite, GoodrichSite, etc., defined? That seems like a very unusual way to code it.


    Also, what has changed between the time that clicking on the logos worked and clicking on the logos not working. Did you upgrade to a newer version of Access, for example?

  10. #10
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    First off, you have the same problem with incorrect syntax in your cmdAdmin_DblClick() sub as you had in the cmdDataEnter_Click sub.

    Next, this code is wrong:
    Code:
    Private Sub cmdExit_Click()
        CurrentDatabase.Close
    End Sub

    Use Application.CloseCurrentDatabase if you want to close your database but remain in Access, itself, or Application.Quit if you want to leave Access altogether.

    That said, the error message

    "Procedure declaration does not match description of event or procedure having the same name."

    usually indicates that you either have a given sub placed in the Form's code module two or more times, or you have it in the code module and have something in the event's property box in the Form's Property Pane. I'd check the Command Button's OnClick or DoubleClick Property Pane for errant characters or macros.

    Of course, the Form itself could be corrupted. Id this problem specific for a given Command Button or does it occur when any Command Button is clicked?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  11. #11
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Code:
    Private Sub cmdAdmin_DblClick()
       Dim strIDAdmin As String
       Dim frmCurrentForm As Form
       If Environ("USERNAME") <> "david.cromer" Then
            msgbox ("You do not currently have administrator rights for this database. Please contact David Cromer, Dept. 549, for questions.")
       Else
            Set frmCurrentForm = Screen.ActiveForm
            DoCmd.Close acForm, "frmCurrentForm", acSaveNo
            DoCmd.OpenForm "frmAdminTools", acNormal, "", "", , acNormal
       End If
    End Sub
    Regarding the code above.

    There are two forms of message box. With parenthesis and with out parenthesis.
    With parenthesis: returns an Integer indicating which button the user clicked to a variable.
    With out parenthesis: displays a dialog box, waits for a button click, then closes.

    Another indication is that the keyword "Msgbox" did not capitalize itself. If you type a line with a keyword in lower case, you move to a different line and the command automatically capitalizes itself, that has valid syntax.

    You should have: (NO parenthesis)
    Code:
    msgbox "You do not currently have  administrator rights for this database. Please contact David Cromer,  Dept. 549, for questions."

    You create a variable as a FORM, "frmCurrentForm", set it to the active form, then try to close it.
    The command "Close" is looking for the NAME (as a text string) of the form, not an object of type form!!

    Modified code
    Code:
    Private Sub cmdAdmin_DblClick()
       '         Dim strIDAdmin As String      '<<unused - commented out
       Dim frmCurrentForm As String    '<< changed to a string
    
       If Environ("USERNAME") <> "david.cromer" Then
       'removed parenthesis
          MsgBox "You do not currently have administrator rights for this database. Please contact David Cromer, Dept. 549, for questions."
       Else
          frmCurrentForm = Screen.ActiveForm.Name  'deleted "SET" from this line
          DoCmd.Close acForm, frmCurrentForm    '<< removed quotes & corrected syntax
          DoCmd.OpenForm "frmAdminTools", acNormal    '<<corrected syntax
       End If
       
    End Sub

  12. #12
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by ssanfu View Post
    [code]

    ...There are two forms of message box. With parenthesis and with out parenthesis.
    With parenthesis: returns an Integer indicating which button the user clicked to a variable.
    With out parenthesis: displays a dialog box, waits for a button click, then closes.

    Another indication is that the keyword "Msgbox" did not capitalize itself. If you type a line with a keyword in lower case, you move to a different line and the command automatically capitalizes itself, that has valid syntax...
    Not quite; actually, the line of code

    Code:
    msgbox ("You do not currently have administrator rights for this database. Please contact David Cromer, Dept. 549, for questions.")

    will execute just fine, and Intellisense will capitalize the 'M' in msgbox, as you move off of the line, as entered above! Just try it! That line is simply not causing an error.

    If, on the other hand, you had entered it, with the parens, as done above, and added any other argument to it, such as

    Code:
    msgBox (""You do not currently have administrator rights for this database. Please contact David Cromer, Dept. 549, for questions."",vbCritical)
    the Access Gnomes will, indeed, balk, refuse to capitalize the 'M,' and refuse to accept the code, telling you that it requires a leading equal sign, in front of it, so that it reads something like

    Code:
    resp = MsgBox (""You do not currently have administrator rights for this database. Please contact David Cromer, Dept. 549, for questions."",vbCritical)

    assigning that returned Integer that was mentioned to the Variable named 'resp.' But that's not the case here.

    As I said, before, the code
    Code:
    Private Sub cmdExit_Click()
        CurrentDatabase.Close
    End Sub

    will definitely cause an error, and keep the code from compiling, because CurrentDatabase hasn't been defined anywhere; have you tried one of the alternative lines I gave you?

    And don't forget to make the changes Steve gave you for the DoCmd.OpenForm "frmAdminTools" line in the cmdAdmin_DblClick event.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  13. #13
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Not quite; actually, the line of code

    Code:

    msgbox ("You do not currently have administrator rights for this database. Please contact David Cromer, Dept. 549, for questions.")
    $%^&*$#@$^
    It's a conspiracy!! The Access Gnomes are out to get me!!

    Thanks Linq.
    Last time I tried it it didn't auto-capitalize. Now it does.... must be my eyes....

  14. #14
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    The one thing that Access has never been accused of is being consistent! All experienced developers have known Access to misbehave, refusing to do some simple task. We spend hours and hours, trouble-shooting it, finally give up, only to find out that the next time when we go back in it works just as it should!

    Just can't let wrong info stay out there; by this time, tomorrow, it would be quoted as gospel on five Access forums...or is it fori? I can never remember the plural!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Open Form or Command Button problem
    By geordie_taz in forum Forms
    Replies: 3
    Last Post: 12-13-2012, 10:09 AM
  2. Command Button Problem is Subform
    By Lupson2011 in forum Access
    Replies: 3
    Last Post: 08-25-2011, 08:39 AM
  3. Command Button
    By BLD21 in forum Access
    Replies: 2
    Last Post: 05-02-2011, 04:47 PM
  4. Replies: 1
    Last Post: 07-27-2010, 02:27 PM
  5. Command Button
    By lannoe in forum Forms
    Replies: 1
    Last Post: 07-01-2010, 01:48 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