Solved why when i change button icon or image in database : erorr message after that The expression may not result in the name of a macro, (1 Viewer)

AHMEDRASHED

Member
Local time
Today, 05:41
Joined
Feb 2, 2020
Messages
59
Hello evrey one

When i add or Change buttons .icon or images in my databas i see below erorr after it :
*The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure]
*There may have been an error evaluating the function, event, or macro*
Note : this erorr disappeared after compile and restart the database every time , and No macro in my database
 

Attachments

  • Screenshot_2.png
    Screenshot_2.png
    7.1 KB · Views: 112
Last edited:
This kind of error has to occur in the context of a form since OnClick is almost exclusively in form context and related to some control on a form.

When I research this, it suggests a class of errors that relate to any of several events, not just "On Click". In all cases, it seems to be related to what has been entered for the failing event property. That is, it relates to giving Access something for the OnClick property that isn't one of the standard options for event activation.

Can you open up the form and take a screenshot to show the Event property list for any control on that form that has something for the On Click event (actually has something in it)? I'm not interested in the controls that don't have an On Click event action listed. If you have a lot of OnClick event links then pick the events for the most recently changed command button.

It COULD be a broken reference, but there has to be more to it than that.

And just a note on etiquette - you don't need bold letters for your entire descriptive text. It is like you are yelling at us when you do that. We can easily forgive you, but please don't make a habit of it. It is a bit annoying.
 
Thank you for your response, @The_Doc_Man. I believe I've identified a few key points :

1. i suspect that the issue may be related to the image type used for buttons, and i have noticed that : changing the icon to image type ( ico or bmp ) format resolved the problem after testing it multiple times.

2. i not using "Option Compare Database" but have now fixed it, and there are currently no errors for now .

3. i have also many OnClick events without error handling, i plan to implement error handling for them.
 
Code:
Option Compare Database

Option Explicit



Private Sub btnCalculator_Click()

Dim calculatorPath As String

calculatorPath = "C:\Windows\System32\calc.exe" ' change the path if necessary

Shell calculatorPath, vbNormalFocus

End Sub



Private Sub btnDemo1_Click()

If IsNull(Me.form1) Then

MsgBox "You do not have permission to open this service", vbInformation, "Notification"

Else

DoCmd.OpenForm (Me.form1)

End If

End Sub



Private Sub btnDemo12_Click()

If IsNull(Me.form12) Then

MsgBox "You do not have permission to open this service", vbInformation, "Notification"

Else

DoCmd.OpenForm (Me.form12)

End If

End Sub



Private Sub btnDemo2_Click()

If IsNull(Me.form2) Then

MsgBox "You do not have permission to open this service", vbInformation, "Notification"

Else

DoCmd.OpenForm (Me.form2)

End If

End Sub



Private Sub btnDemo3_Click()

If IsNull(Me.form3) Then

MsgBox "You do not have permission to open this service", vbInformation, "Notification"

Else

DoCmd.OpenForm (Me.form3)

End If

End Sub





Private Sub btnDemo9_Click()

If IsNull(Me.form9) Then

MsgBox "You do not have permission to open this service", vbInformation, "Notification"

Else

DoCmd.OpenForm (Me.form9)

End If

End Sub



Private Sub btnSettings_Click()

DoCmd.CLOSE

DoCmd.OpenForm "frmSettings"

End Sub



Private Sub cmdAddNewReminders_Click()

DoCmd.OpenForm "frmCreateReminders"

End Sub



Private Sub cmdExit_Click()

DoCmd.Quit

End Sub



Private Sub cmdfrmVAT_Click()

    ' Get the current user's name from the frmHome form

    Dim userFromForm As String

    userFromForm = Forms!frmhome!userName

 

    ' Check if the user's name is not equal to "Ahmed"

    If userFromForm <> "Ahmed" Then

        ' Display a message and don't open frmVAT

        MsgBox "You don't have access to this form.", vbExclamation, "Access Denied"

    Else

        ' Open the frmVAT form

        DoCmd.OpenForm "frmVAT", acNormal

    End If

End Sub



Private Sub CmdRASHED_Click()

    MsgBox "Designed by Ahmed Rashed. If you like, please make for me one espresso without sugar.", vbInformation, "RASHED SOFTWARE"

End Sub







Private Sub cmdReminders_Click()

    ' On Click of the cmdReminders button, check Reminders table for any uncompleted Reminders



    Dim intStore As Integer

    Dim userName As String



    ' Get the username from the form

    userName = Forms!frmhome!userName



    ' Count of uncompleted Reminders that are past the Expected Completion Date

    intStore = DCount("[RemindersID]", "[tblReminders]", "[RemindersDate] <= Now() AND [isComplete] = 0 AND [userName] = '" & userName & "'")



    ' Check if the username matches a specific value (you can replace "YourUsername" with the desired username)

    If userName = Forms!frmhome!userName Then

        ' If the username matches, check the count of uncompleted Reminders

        If intStore = 0 Then

            MsgBox "There are no uncompleted reminders for you."

        Else

            If MsgBox("There are " & intStore & " Reminders " & _

                vbCrLf & vbCrLf & "Would you like to see these now?", _

                vbYesNo, "Reminder") = vbYes Then

                DoCmd.OpenForm "frmReminders"

            End If

        End If

    Else

        ' Handle the case where the username does not match

        MsgBox "You are not authorized to view the reminders."

    End If

End Sub



Private Sub cmdSendMessage_Click()

DoCmd.OpenForm "frmsendMessage", acNormal, "", "", , acNormal

End Sub



Private Sub cmdSwitchUser_Click()

DoCmd.CLOSE

DoCmd.OpenForm "frmLogin"

End Sub



Private Sub cmdViewMessage_Click()

    ' Get the current user's name from the frmHome form

    Dim userFromForm As String

    userFromForm = Forms!frmhome!userName

 

    ' Check if the user's name is not equal to "Ahmed"

    If userFromForm <> "Ahmed" Then

        ' Display a message and don't open frmVAT

        MsgBox "You don't have access to this form.", vbExclamation, "Access Denied"

    Else

        ' Open the frmVAT form

        DoCmd.OpenForm "frmViewMessage", acNormal

    End If

End Sub







Private Sub Form_Load()

DoCmd.Maximize

Dim db As Database

Dim rst As Recordset

Dim userID As Integer

Dim intStore As Integer

Dim userName As String

'This is going to get the userID for the current login from the Temp Table

userID = DLookup("userID", "tTemp", "tempID=1")

Set db = CurrentDb()

'This will collect the information of the current login from the login Table

Set rst = db.OpenRecordset("SELECT *FROM tlogin Where userID=" & userID)

'We are filling the text area on the Demo menu so that we easly access the forms that the user is allowed to use

Me.userName = rst!userName

If rst!allowUserAccessSys = True Then

Me.btnSettings.Visible = True

Else

Me.btnSettings.Visible = False

End If

If rst!form1Allowed = True Then

    Me.form1 = rst!form1

    Me.FormName1 = rst!FormName1

    If IsNull(rst!FormName1) Then

       'Do nothing

    Else

        Me.btnDemo1.Caption = Me.FormName1

    End If

Else

    Me.form1 = Null

    Me.FormName1 = Null

End If





If rst!form11Allowed = True Then

    Me.form11 = rst!form11

    Me.FormName11 = rst!FormName11

     If IsNull(rst!FormName11) Then

       'Do nothing

    Else

    Me.btnDemo11.Caption = Me.FormName11

    End If

Else

    Me.form11 = Null

    Me.FormName11 = Null

End If



If rst!form12Allowed = True Then

    Me.form12 = rst!form12

    Me.FormName12 = rst!FormName12

     If IsNull(rst!FormName12) Then

       'Do nothing

    Else

    Me.btnDemo12.Caption = Me.FormName12

    End If

Else

    Me.form12 = Null

    Me.FormName12 = Null

End If



'We are filing the menuBar

Set rst = db.OpenRecordset("SELECT *FROM tMenu Where menuID=1")

If IsNull(rst!menuBarItemName1) Then

    Me.NavigationButton1.Visible = False

Else

  Me.NavigationButton1.Caption = rst!menuBarItemName1

  Me.menuBarFrmToOpen1 = rst!FormToOpen1

End If



If IsNull(rst!menuBarItemName2) Then

    Me.NavigationButton2.Visible = False

Else

  Me.NavigationButton2.Caption = rst!menuBarItemName2

  Me.menuBarFrmToOpen2 = rst!FormToOpen2

End If





If IsNull(rst!menuBarItemName10) Then

    Me.NavigationButton10.Visible = False

Else

  Me.NavigationButton10.Caption = rst!menuBarItemName10

  Me.menuBarFrmToOpen10 = rst!FormToOpen10

End If



If DLookup("showMenuC", "tstartupForm", "startupID=1") = True Then

    Me.menuCList.Visible = True

End If



    ' On Load of the switchboard (frmhome), check Reminders table for any uncompleted Reminders



' Get the username from the form

userName = Forms!frmhome!userName



' Check the username and show/hide images accordingly

If userName = "ALAA" Then

    Me.ImageALAA.Visible = True

ElseIf userName = "MAHER" Then

    Me.ImageMAHER.Visible = True

ElseIf userName = "AHMED" Then

    Me.ImageAHMED.Visible = True

End If





    ' Count of uncompleted Reminders that are past the Expected Completion Date

    intStore = DCount("[RemindersID]", "[tblReminders]", "[RemindersDate] <= Now() AND [isComplete] = 0 AND [userName] = '" & userName & "'")



    ' Display the reminder count on the form

    Me.ReminderCount.Caption = " " & intStore



    ' Optionally, you can decide whether to open the reminders form or not

    ' If intStore > 0 Then

    '     DoCmd.OpenForm "frmReminders"

    ' End If

 

End Sub





Private Sub Form_Timer()

    Const IDLESECONDS = 1800 ' 1800 seconds of idle time

    Static PrevControlName As String, PrevFormName As String, ExpiredTime

    Dim ActiveFormName As String, ActiveControlName As String, ExpiredSeconds

 

    On Error Resume Next

    ActiveFormName = Screen.ActiveForm.Name

    If Err Then ActiveFormName = "No Active Form": Err = 0

 

    ActiveControlName = Screen.ActiveControl.Name

    If Err Then ActiveControlName = "No Active Control": Err = 0

 

    If (PrevControlName = "") Or (PrevFormName = "") _

        Or (ActiveFormName <> PrevFormName) _

        Or (ActiveControlName <> PrevControlName) Then

        PrevControlName = ActiveControlName

        PrevFormName = ActiveFormName

        ExpiredTime = 0

    Else

        ExpiredTime = ExpiredTime + Me.TimerInterval

    End If

 

    ExpiredSeconds = ExpiredTime / 1000

    If ExpiredSeconds >= IDLESECONDS Then

        ExpiredTime = 0

        Application.Quit ' Quit the application after 1800 seconds of idle time

    End If

Me.Cmes.Requery

Me.AA.Requery

Me.Nmes.Requery



If Me.Cmes.value > 0 Then

DoCmd.OpenForm "frmMessages"

Me.TimerInterval = 0

End If

End Sub

Private Sub Image274_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    MsgBox "Designed by Ahmed Rashed. If you like, please make for me one espresso without sugar.", vbInformation, "RASHED SOFTWARE"

End Sub





Private Sub menuCList_AfterUpdate()

Dim db As Database

Dim rst As Recordset

Set db = CurrentDb()

Set rst = db.OpenRecordset("SELECT *FROM tMenuC Where menuCID=" & menuCList)

Me.menuBarFrmToOpen11 = rst!formToOpen

If IsNull(Me.menuBarFrmToOpen11) Then

MsgBox "You do not have permission to open this service", vbInformation, "Notification"

Else

DoCmd.OpenForm (Me.menuBarFrmToOpen11)

End If

End Sub



Private Sub NavigationButton1_Click()

If IsNull(Me.menuBarFrmToOpen1) Then

MsgBox "You do not have permission to open this service", vbInformation, "Notification"

Else

DoCmd.OpenForm (Me.menuBarFrmToOpen1)

End If

End Sub



Private Sub NavigationButton9_Click()

If IsNull(Me.menuBarFrmToOpen9) Then

MsgBox "You do not have permission to open this service", vbInformation, "Notification"

Else

DoCmd.OpenForm (Me.menuBarFrmToOpen9)

End If

End Sub



Private Sub ReminderCount_Click()

    ' When ReminderCount is clicked, call the cmdReminders_Click procedure

    Call cmdReminders_Click

End Sub
 
Last edited:
I'm glad you have resolved the problem by switching to a proper image type. What you displayed in #4 (the code) wasn't what I had requested, but if you have a workable answer, then we can leave it as-is and not worry about it.
 
I'm glad you have resolved the problem by switching to a proper image type. What you displayed in #4 (the code) wasn't what I had requested, but if you have a workable answer, then we can leave it as-is and not worry about it.
Thank you The_Doc_Man , its work fine now without any erorr
 

Users who are viewing this thread

Back
Top Bottom