an access problem:OutputTo not work in access 2007 - ms-access-2007

i Have used this code in access 2010 for genrating pdf file
DoCmd.OutputTo acOutputReport, "Graph_report2", ".pdf", "C:\Graph_report2.pdf", True
it is working fine in access 2010 but when i open my access database in access 2007 it gives Runtime error 2501 that 'The OutputTo action was cancelled' and not pdf file is open.
Big problem !what i do? Plz Help

DoCmd.OutputTo acOutputReport, "Graph_report2", ".pdf", "C:\Graph_report2.pdf", True
should be:
DoCmd.OutputTo acOutputReport, "Graph_report2", acFormatPDF, "C:\Graph_report2.pdf", True
Rob

Can I add that apart that one needs to install an add in for PDF output and then start Access 2007, http://www.microsoft.com/en-us/download/details.aspx?id=9943
If one tries to save the file in a directory that does not exist, this error will also pop up.
Here is a function for PDF output:
Function PrintToPDF(SrcReport As String, DestPath As String, DestFile As String, ShowPdf As Boolean)
On Error GoTo PrintToPDF_Err
'ScrReport = The report Name to output as PDF
'DestPath = Destination path for PDF file e.g. C:/DatabaseReports/Financial/
'DestFile = File name for the PDF file being created, but without the file extension, one can add date to it
'Showpdf = launch pdf viwer and display this PDF output
DoCmd.OutputTo acOutputReport, SrcReport, "PDFFormat(*.pdf)", DestPath & DestFile & ".pdf", ShowPdf, "", 0, acExportQualityPrint
PrintToPDF_Exit:
Exit Function
PrintToPDF_Err:
MsgBox Error$
Resume PrintToPDF_Exit
End Function

Related

Printing report with access generate white square

I am trying to print an access report with PDF creator but a strange problem is happening:
If I print the report with PDF creator I get a white square in the report (see the blow instruction):
DoCmd.OutputTo acOutputReport, "E_Dossier", acFormatPDF, first & strReportName, False, , 0 ,
but if I open it with this instruction instead, the report is correct and I don't have white squares.
DoCmd.OpenReport "E_Dossier" ' , acViewPreview
Any ideas please?
I have had issues like that in the past. What I do is I open the report in hidden preview, then export to PDF and then close the preview. That seems to deal with most of the weird differences between print and export.
Edit: This is a function I use to generate PDFs
Public Sub PrintReportPDF(ReportName As String, Filename As String, Optional ReportArgs As String = "", Optional WhereCondition As String = "")
DoCmd.OpenReport ReportName, acViewPreview, , WhereCondition, , ReportArgs
DoCmd.OutputTo acOutputReport, "", acFormatPDF, Filename, False
DoCmd.Close acReport, ReportName
End Sub
Another thing to check is that you have a regular default printer (one that would print the report properly if the report was printed to it).
i have joined an example of generated white square #Marcucciboy2

How to save file to shared drive on network with VBA

Using trying to write code that will save a file to a shared drive on our network. If I use a mapped drive as the destination location (i.e. R:...) then it works with no problem. BUT, not everyone is mapped to that, so I want to be able to save the file use \ourserver\serverfolder ...
when I try to replace "R:\" & filename with "\ourserver\serverfolder\" & file name, I get an error 76, "File Path Not Found."
In essence, the question is how do I save a file to a shared drive, using the shared drive path, via vba?
the sample code takes sourcefile "C:\houses\myhouse.pdf" ... and wants to save to destination file "\ourserver\serverfolder\anotherfolder\myhouse.pdf"
Private Sub CopyRenameFile(ByRef SourceFile As String, ByRef DestinationFile As String)
On Error Resume Next
FileCopy SourceFile, DestinationFile
If Err.Number <> 0 Then
Call LogError(Err.Number, Err.Description, "CopyRenameFile() Class FileMoverMove", , True)
MsgBox "Copy error: " & SourceFile
End If
On Error GoTo 0
End Sub
You are close as you just miss one leading backslash in the UNC path:
DestinationFile = "\\ourserver\serverfolder\" & file name

saving an external data file using writeAllText

I'm trying to save data to an external data file on visual basic using visualstudio 2013, so far I've found various methods to do this but they all get stuck on the same problem
"An unhandled exception of type 'System.UnauthorizedAccessException' occurred in >mscorlib.dll
Additional information: Access to the path 'C:\test.txt' is denied."
The current method I'm using is the following code
Dim filename As String
filename = InputBox("Please Enter a Filename", "Enter Filename", "")
If filename = "" Then
MsgBox("Please Enter a value to save", vbOKOnly, "Error")
Else
filename = "C:\" + filename + ".txt"
File.WriteAllText(filename, "Accesories list Items")
End If
The Windows C Drive is inaccessible by any external program (pretty sure MS programs can access it). Try using "C:\temp\test.txt" If that fails then there is a problem. Otherwise it's probably because you're not allowed to access that area of Windows.

Open Word Document From Dynamic Directory VB.Net

I have a program for which I have developed a user guide. I have placed this user guide within the project directory. I created a MenuStrip Item by which to open the user guide in Word on the user's machine. I was successfully able to do this with the following code:
Try
userGuide = MSWord.Documents.Open("C:Users\administrator\Documents\VisualStudio2010\Project3\UserGuide.doc")
MSWord.WindowState = Word.WdWindowState.wdWindowStateNormal
MSWord.Visible = True
Catch ex As Exception
MsgBox("An error has prevented the document from opening. The document may not be available." & vbCrLf & vbCrLf & _
"Please try one of the following options:" & vbCrLf & _
"- Check to see if the document is already open" & vbCrLf & _
"- Restart the program")
End Try
The problem is, the path used to open the file will not exist on the users machine. This is a standalone system, so no file share can be created in which to place the document, therefore no common path can be coded.
Is there a way to code dynamic paths? Perhaps something like:
userGuide = MSWord.Documents.Open("%windir%\UserGuide.doc")
Thanks!
if the document will be stored relative to the install path of the application executable, then start with the path of the exe:
Dim path As String
path = System.IO.Path.GetDirectoryName( _
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
Dim docPath as String;
docPath = Path.Combine(path,"UserGuide.doc");

VBA Shell command always returns "File Not Found"

I'm using VBA for MS Access in order to link a small C# app to my database as a helper tool. I have tried a couple of different ideas from stackoverflow itself, including the ShellAndWait utility and another on that page.
I have a button on a form. When you click this button, it should run another application that I am currently storing in %APPDATA%/program/
This is the code that is currently active:
Private Sub BtnImport_Click()
Dim file As String
Dim hProcess as Long
file = Environ("APPDATA") & "\program\component_import.exe"
'This is the standard version, which apparently does nothing at this time.
hProcess = Shell(file, vbNormalFocus)
'This is the RunApplication version I got from here earlier. It ends
'with "Successfully returned -532462766
import_funcs.RunApplication(file)
'This is the ShellAndWait version, which gives me a "File not Found" error
import_funcs.ShellAndWait(file, 0, vbNormalFocus, AbandonWait)
End Sub
I had changed the original shell out for both the ShellAndWait module and another similar module. Neither of those options work any differently in terms of my application not starting.
I have double-checked that "file" is correct (It points to C:\Users\Me\AppData\Roaming\program\component_import.exe). I have double-checked to make sure that my app is in the correct location.
It runs fine if I double-click from file explorer. It says Run-time error '53': File not found. whenever I attempt to run it from MS Access.
Any suggestions?
Edit: As an aside, the path itself does not contain any spaces.
Edit: Added some additional code.
Link to first pastebin: RunApplication pastebin
Link to second pastebin: ShellAndWait pastebin
I found sometimes folder names with spaces throws error when using shell command.
eg: C:\My Folder\appl.exe
make it:
C:\MyFolder\appl.exe
Also can check for a valid path:
The following code checks the folder where chrome.exe residing and calling www.google.com from there by passing url as argument:
Public Sub Display_Google()
Dim chromePath As String
chromePath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
If FileExists(chromePath) Then
Shell (chromePath & " -url" & " " & "www.google.com"), vbMaximizedFocus
Else
chromePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
Shell (chromePath & " -url" & " " & "www.google.com"), vbMaximizedFocus
End If
End Sub
Public Function FileExists(ByVal FileName As String) As Boolean
On Error Resume Next
FileExists = Not CBool(GetAttr(FileName) And (vbDirectory Or vbVolume))
On Error GoTo 0
End Function