Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA code working for me but not for users

Status
Not open for further replies.

JoyLopez

Programmer
Mar 2, 2016
2
0
0
US
Hello everyone! I have a database that is used by multiple users. Every button and module works as intended except one. I have a hyperlink field that when clicked, it opens a report using the selected record's ID, attaches it to an email and closes the report afterwards. It works wonderful for me, but not for the other users. I have checked that all MS Access, Outlook and Windows versions are the same, libraries are the same, etc. It's the exact same front end, and all other modules work just fine.

I found out the problem is that when clicked, it doesn't run the "Open report" command at all. Any ideas?

Here's the code:
Code:
Private Sub txtOpen_Click()

On Error GoTo ErrorHandler

  Me.Dirty = False
   'error check if the ID is null
If IsNull(Me!Req_ID) Then
MsgBox "Please select a valid record", _
vbOKOnly, "Error"
Exit Sub
End If
'Open report so it passes on the ID and shows the Doc for selected record
DoCmd.OpenReport "Qualification Document", acViewReport, , _
"Req_ID = " & Me!Req_ID
'Attaches the report to an email ready to send
 DoCmd.SendObject acSendReport, "Qualification Document", acFormatPDF, _
     Me.[E-mail Address], , , "Document for " & [Contact Name], "Find attached the document.", True
'close report after sending email
   DoCmd.Close acReport, "Qualification Document", acSaveNo
   MsgBox "Message Sent Successfully."
   
Cleanup:
   DoCmd.Close acReport, "Qualification Document", acSaveNo
   Exit Sub
'catches error if the user closes email without sending
ErrorHandler:
   Select Case Err.Number
     Case 2501
       MsgBox "Email message was Cancelled."
     Case Else
       MsgBox Err.Number & ": " & Err.Description
   End Select
   Resume Cleanup

End Sub
 
I found out the problem is that when clicked, it doesn't run the "Open report" command at all. Any ideas?

How did you find out? What is it doing instead? Does it error, does it skip it?
 
Also while I have seen people use docmd.open report to filter before doing something else with the report like e-mail it or export it, I always have always included my filter logic in the query in those cases and used send or export directly. This may just be a style and way I learned it thing but I have long running success the other way.
 
I took the "Error Handler" out, and when the person clicks on the field, it stops the macro and highlights in yellow this portion: "DoCmd.OpenReport "Qualification Document", acViewReport, , _"

With the error handler, when the person clicks on the field, nothing opens and it goes directly to the "Email message was Cancelled." error message.
 
A phantom break point.

Sometimes break points don't clear correctly. Try setting a break point there, saving, close open, clear the break point and resave.

The one person I read with speculation of the cause is setting breakpoints when the code is executing/stepping through it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top