chuckcoleman
Registered User.
- Local time
- Today, 17:28
- Joined
- Aug 20, 2010
- Messages
- 377
Hi, I'm stumped. My code does two things.
1. It creates a PDF copy of a report and places that in a folder
2. It adds to the [Attachments Table] a row for the customer ID, the Job ID, the Hyperlink and the RawFileName which is the text of the file name
When the code runs, it displays the report correctly. After I view the report, when I open a form which has a simple query of the files in the [Attachments Table], it shows them correctly. When I hover over the file I'm interested in opening, it shows the correct file name. However, when I click on the Hyperlink, it always opens the PREVIOUS file. I can't figure out why it is opening the previous file and not the one I clicked on. In the attached picture, if I click on the top record that ends in 48-36.pdf, it opens the previous file that ends in 45-11.pdf. I'm stumped.
Thoughts?
1. It creates a PDF copy of a report and places that in a folder
2. It adds to the [Attachments Table] a row for the customer ID, the Job ID, the Hyperlink and the RawFileName which is the text of the file name
When the code runs, it displays the report correctly. After I view the report, when I open a form which has a simple query of the files in the [Attachments Table], it shows them correctly. When I hover over the file I'm interested in opening, it shows the correct file name. However, when I click on the Hyperlink, it always opens the PREVIOUS file. I can't figure out why it is opening the previous file and not the one I clicked on. In the attached picture, if I click on the top record that ends in 48-36.pdf, it opens the previous file that ends in 45-11.pdf. I'm stumped.
Thoughts?
Code:
Dim DateForQuote As String
Dim DestPath As String
Dim CustomersID As Integer
Dim CustomerIDDetail As String
Dim JobIDNbr As String
Dim strSelectedFile As String
Dim strSelectedFileSubDirectory As String
Dim strHyperlinkFile As String
Dim filename As String
Dim srcFile As String
On Error GoTo PrintPreviewQuote_Err
DateForQuote = ""
DateForQuote = Format(Now, "mm-dd-yyyy hh-mm-ss")
MsgBox ("1-The DateForQuote is: " & DateForQuote)
If IsNull(Me.JobIDX) Then
MsgBox "There aren't any details for this job. You have to enter information in the Description field to get a quote."
Exit Sub
Else
Me.SelectedX = -1
DoCmd.RunCommand acCmdSaveRecord
srcFile = "Quote Report with Contacts"
DestPath = "C:\Wood\Attachments\"
CustomersID = Forms![Detail Form]![CustomerIDY]
CustomerIDDetail = Forms![Detail Form]![CustomerIDX]
JobIDNbr = Forms![Detail Form]![JobIDX]
strSelectedFile = CustomerIDDetail & "-" & JobIDNbr & "-" & DateForQuote & ".pdf"
MsgBox ("2-strSelectedFile is: " & strSelectedFile)
strSelectedFileSubDirectory = "C:\Attachments" ' & LNameLookUp & "-" & [CustomerIDX] & "-" & [JobIDX] & ".pdf"
strHyperlinkFile = "C:\Wood\Attachments\" & strSelectedFile
ShowPDF = False
filename = Application.CurrentProject.Path & strSelectedFileSubDirectory
MsgBox ("3b-strHyperLinkFIle is: " & strHyperlinkFile)
DoCmd.OutputTo acOutputReport, srcFile, "*.pdf", strHyperlinkFile, ShowPDF, "", 0, acExportQualityPrint
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO [Attachments Table] (JobID, CustomerID, FileN, RawFileName) VALUES" _
& "(' " & JobIDNbr & " ', ' " & CustomersID & " ', ' " & strSelectedFile & "#" & strHyperlinkFile & "#" & " ', ' " & strSelectedFile & " ')"
DoCmd.SetWarnings True
DoCmd.OpenReport "Quote Report with Contacts", acViewPreview
DoCmd.SelectObject acForm, "Detail Form"
DoCmd.RunCommand acCmdSaveRecord
DoCmd.SelectObject acReport, "Quote Report with Contacts"
Me.Text57.Requery
Me.SelectedX = 0
End If