PDA

View Full Version : Macro Button Crashes Access



gadget01
06-26-2017, 01:13 AM
Hi,
I have a macro that runs when a button is clicked, this works fine initially. Eventually, over time (days/weeks), something goes wrong and it then causes the Access application to present the dialog box saying that it has stopped responding. I have this on a works networked PC and wonder if that can be the problem. I can fix it by opening the macro and resaving it (no changes required). This works on my version but not on other PC's often. Could this possibly be caused by O.S updates or overwriting the database with design changed version. The design changes not related to this button. I guess it is linked to some sort of verification step which maybe disrupted by something. Your help appreciated as it is becoming a pain to rectify.

Thanks
gadget01

my button code:


Private Sub Command87_Click()
strInput = InputBox("Please note:" & vbCrLf & "Using other than the green Data Entry buttons on this menu page to edit should not be done if your edit requires progressing the waste through one of the waste diposal steps" & vbCrLf & vbCrLf & "If you really must edit a waste item then beware of your actions.... " & vbCrLf & vbCrLf & "Enter Password:")

If strInput = "****" Then
DoCmd.OpenForm "Admin Menu"
Else: MsgBox ("Sorry, you do not have access privilege!"): Exit Sub
End If
End Sub

OBP
06-26-2017, 03:38 AM
I would suggest that the first thing you need is to add some Error Trapping and reporting VBA to your Macro to establish if it is something in the code causing it or it is an external issue.

I weould change your code to this


Private Sub Command87_Click()
On Error GoTo Eventerror

strInput = InputBox("Please note:" & vbCrLf & "Using other than the green Data Entry buttons on this menu page to edit should not be done if your edit requires progressing the waste through one of the waste diposal steps" & vbCrLf & vbCrLf & "If you really must edit a waste item then beware of your actions.... " & vbCrLf & vbCrLf & "Enter Password:")

If strInput = "****" Then
DoCmd.OpenForm "Admin Menu"
Else: MsgBox ("Sorry, you do not have access privilege!"): Exit Sub
End If
Exit Sub

Eventerror:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description

'Use this and come back when the error occurs again with any message that it may develop.
End Sub

I also notice that the strInput you are using is not dimensioned, I am not sure if that would have an effect or not.

gadget01
06-26-2017, 04:43 AM
Thanks for your reply, both good points, I will try the following. So far no errors.

Private Sub Command87_Click()
Dim strInput As String
On Error GoTo Eventerror

strInput = InputBox("Please note:" & vbCrLf & "Using other than the green Data Entry buttons on this menu page to edit should not be done if your edit requires progressing the waste through one of the waste diposal steps" & vbCrLf & vbCrLf & "If you really must edit a waste item then beware of your actions.... " & vbCrLf & vbCrLf & "Enter Password:")

If strInput = "****" Then
DoCmd.OpenForm "Admin Menu"
Else: MsgBox ("Sorry, you do not have access privilege!"): Exit Sub
End If

Eventerror:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub

SamT
06-26-2017, 10:10 AM
Gentlemen. If you select all your code, then click the # icon in the Post Editor menu, it will place Code Formatting Tags around your code, so that it looks like the above three messages.

Note that I also added some white space above to break your codes into logical segments.

gadget01
06-27-2017, 12:39 AM
Gentlemen. If you select all your code, then click the # icon in the Post Editor menu, it will place Code Formatting Tags around your code, so that it looks like the above three messages.

Note that I also added some white space above to break your codes into logical segments.


I didn't know that thanks, it looks much better. I'll give it a try.