How to I use a string in this code??

anb001

Registered User.
Local time
Today, 23:36
Joined
Jul 5, 2004
Messages
197
How do I use a string for filepath in this code??

I'm using Lebans code for converting reports to pdf files. In the code you can specifiy the OutputFilename (the path and filename). See below code (top part is shown):

Code:
Public Function ConvertReportToPDF( _
Optional RptName As String = "rptDailyReport", _
Optional SnapshotName As String = "", _
Optional OutputPDFname As String = "c:\Testreport.pdf", _
Optional ShowSaveFileDialog As Boolean = False, _
Optional StartPDFViewer As Boolean = False, _
Optional CompressionLevel As Long = 0, _
Optional PasswordOpen As String = "", _
Optional PasswordOwner As String = "", _
Optional PasswordRestrictions As Long = 0, _
Optional PDFNoFontEmbedding As Long = 0, _
Optional PDFUnicodeFlags As Long = 0 _
) As Boolean

In above case, the filename and path is "c:\Testreport.pdf". However, can I use a string there, if I don't want to hard code the path/name???

i have the filepath and name in a tabel, and can get that into a string like thing:

Code:
Dim strTest As String

strTest = DLookup("FilePath", "tblEmail")

But when I use it with above Public Function, it doesn't work.

Can someone advise how I use the string with filepath/name, in stead of hard coding same?

Thanks.
 
Last edited:
I also have below code for sende emails with attached files.

Code:
Private Sub cmdSendMail_Click()


'this is a sample usage routine
On Error GoTo Err_Handler
Dim strTemp As String
Dim varAttach As Variant
Dim strRecTo(1, 0) As String
Dim lngCount As Long
Dim varProxies As Variant
Dim cGW As GW

Set cGW = New GW
With cGW
  .Login
  .BodyText = [txtEmailBody]
  .Subject = [txtEmailSubject]
  .RecTo = [txtEmailTO]
  .RecCc = [txtEmailCC]
  .FileAttachments = varAttach
  .FromText = "test@mail.com"
  .Priority = "Normal"
  strTemp = .CreateMessage
  .ResolveRecipients strTemp
  If IsArray(.NonResolved) Then MsgBox "Some unresolved recipients."
  .SendMessage strTemp
  .DeleteMessage strTemp, True
End With

Exit_Here:
  Set cGW = Nothing
  
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "frmStart"
  
  
  Exit Sub


Err_Handler:
  MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical
  Resume Exit_Here

End Sub

If I insert:

Code:
Dim strFile As String
strFile = "c:\TestReport.pdf"

And change the 'VarAttach' variant to:

Code:
varAttach = strFile

It also works fine.

But if try to create a string as in my first post, by using DLookup to get the path, it doesn't work. I have also tried updating the filepath into a textbox, and using [txtFilePath], to get the path, but that doesn't work either.

Are there anything special about file paths when used in code. Can't it be "picked up" from a table and used in vba code????

I do hope that somebody can advise what to do.

Thanks.
 
Read your previous thread properly and check the demo

Keep this section of Lebans code as is:
Code:
Public Function ConvertReportToPDF( _
Optional rptname As String = "", _   'DO NOT PUT ANYTHING HERE!!!!
Optional SnapshotName As String = "", _
Optional OutputPDFname As String = "", _  'DO NOT PUT ANYTHING HERE!!!!
Optional ShowSaveFileDialog As Boolean = False, _
Optional StartPDFViewer As Boolean = True, _
Optional CompressionLevel As Long = 0, _
Optional PasswordOpen As String = "", _
Optional PasswordOwner As String = "", _
Optional PasswordRestrictions As Long = 0, _
Optional PDFNoFontEmbedding As Long = 0, _
Optional PDFUnicodeFlags As Long = 0 _
) As Boolean
You call this function from your code using something like this:
Code:
Dim strTest As String
dim strReport as string
strTest = DLookup("FilePath", "tblEmail")
strReport = "<Report Name here>"

blRet = ConvertReportToPDF(strReport, vbNullString, strtest, True, False, 150, "", "", 0, 0, 0)
 
I tried your suggestion (using your example database), and if I write like this:

Code:
filename = "C:\TestReport.pdf"

in stead of:

Code:
filename = GetSaveFilePDF() 'module

as you used, it still works ok. The pdf is saved as '"C:\TestReport.pdf".

However, if I use this code:

Code:
filename = DLookup("FilePath", "tblEmail")

(and here the FilePath is saved in the table as "C:\TestReport.pdf"), the code is still running, and the msgbox pops up in the end stating everthing is ok. But nothing is printed in this case. And that is what puzzles me.
 
This is getting strange.

Again with your example, I added a text box (txtPath), and as the controlsource, I wrote [= C:\Daily Report.pdf] (without brackets), and then:

Code:
filename = [txtPath]

That worked fine. I then changed the txtpath controlsource to 'FilePath' field from the tblEmail (which I made the forms recordsource). Looking at the txtPath when running the code, there was no difference, but when clicking the button, no pdf was created.

It's like it won't accept the path when it comes from the table. But when the path is written somewhere in the vba code or perhaps directly as a controlsource, then it works.

Can anyone tell me why that is???

/Anders
 
Sometimes one has to learn the hard way!

Found the problem. The code I'm using to store the file path in the table, accidently had a 'space' in front of the path. After having spent hours, I finally found it, and after deleting that 'space' everting works as it should. I'm fealing at bit silly now, but guess that's just life now and again :-)
 

Users who are viewing this thread

Back
Top Bottom