Microsoft KB Archive/173334: Difference between revisions
m (Text replacement - """ to """) |
m (Text replacement - "&" to "&") |
||
Line 111: | Line 111: | ||
.Filter = _ | .Filter = _ | ||
"MS-DOS Text (*.txt)|*.txt|Rich Text Format (*.rtf)|*.rtf" _ | "MS-DOS Text (*.txt)|*.txt|Rich Text Format (*.rtf)|*.rtf" _ | ||
& | & "|Microsoft Excel (*.xls)|*.xls" | ||
.FilterIndex = 1 | .FilterIndex = 1 | ||
Line 145: | Line 145: | ||
Resume Export_Exit | Resume Export_Exit | ||
Else | Else | ||
MsgBox Err.Number & | MsgBox Err.Number & ", " & Err.Description | ||
End If | End If | ||
Resume Export_Exit | Resume Export_Exit |
Latest revision as of 12:29, 21 July 2020
Article ID: 173334
Article Last Modified on 1/20/2007
APPLIES TO
- Microsoft Access 97 Standard Edition
- Microsoft Office 97 Developer Edition
This article was previously published under Q173334
Moderate: Requires basic macro, coding, and interoperability skills.
SYMPTOMS
When you use the OutputTo method or RunCommand method in a Microsoft Access 97 run-time application, you may receive the following error message:
-or-
This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to the "Building Applications with Microsoft Access 97" manual.
CAUSE
Your computer has only a run-time version of Microsoft Access 97 installed, and you are using an action or method that prompts the user for an input or output file name. For example, if you use the OutputTo method and leave the Outputfile argument blank, Microsoft Access prompts you for an output file name.
RESOLUTION
Explicitly supply the file name so that Microsoft Access does not have to prompt the user for one. If you want to prompt the user for a file name, you can use the ShowOpen or ShowSave methods of the Common Dialog ActiveX control.
The following steps demonstrate how to use the Common Dialog ActiveX control to prompt the user for an output file name and type, and then how to supply it to the OutputTo method.
- Start Microsoft Access 97.
- Open the sample database Northwind.mdb.
- Open a new, blank form in Design view.
- On the Insert menu, click ActiveX Control.
- In the Insert ActiveX Control dialog box, select Microsoft Common Dialog Control, version 5.0, and then click OK.
- Set the Name property of the Common Dialog control to cmndlg.
- Add a command button to the form, and set the Name property to Command0.
Set the command button's OnClick property to the following event procedure:
Private Sub Command0_Click() Dim oCmnDlg As CommonDialog Dim strFormat As String Dim strFileName As String Set oCmnDlg = Me!cmndlg.Object On Error GoTo Export_Err With oCmnDlg ' Clear the file name before prompting. .FileName = "" ' Prompt the user if the file already exists. .flags = cdlOFNOverwritePrompt + cdlOFNHideReadOnly ' Determine if the cancel button was pressed. .CancelError = True .Filter = _ "MS-DOS Text (*.txt)|*.txt|Rich Text Format (*.rtf)|*.rtf" _ & "|Microsoft Excel (*.xls)|*.xls" .FilterIndex = 1 ' Default the initial directory to "C:\My Documents". .InitDir = "C:\My Documents" .ShowSave ' Determine what file type was selected; then save the ' file in that format. Select Case .FilterIndex Case 1 ' MS-DOS Text Format. strFormat = acFormatTXT Case 2 ' Rich Text Format. strFormat = acFormatRTF Case 3 ' Microsoft Excel Format. strFormat = acFormatXLS End Select strFileName = .FileName End With DoCmd.OutputTo acOutputTable, "Customers", _ strFormat, strFileName Exit Sub Export_Exit: Exit Sub Export_Err: ' Check to see if the cancel button was pressed. If Err.Number = 32755 Then Resume Export_Exit Else MsgBox Err.Number & ", " & Err.Description End If Resume Export_Exit End Sub
- Close and save the form as Form1.
- On the Tools menu, click Startup.
- In the Startup dialog box, select the Form1 form from the Display Form combo box, and then click OK.
- Close the database.
- Use the ODE Setup Wizard to create a new set of disk images for the application. Add Northwind.mdb and Comdlg32.ocx to the list of files to distribute with the application. Select Northwind.mdb as the application's main file, and create a shortcut that uses the Run-time option to open Northwind.mdb.
- Install the application on a computer that has never had the retail version of Microsoft Access 97 installed.
- Start the application. When the startup form appears, click the command button.
- Select an output file name, and a file type from the Save As Type list, and then click Save.
Note that the Customers table is saved to the file name and type that you selected in the Common Dialog ActiveX control.
MORE INFORMATION
Using the following arguments of the RunCommand method result in a prompt for an input or output file name:
acCmdCreateReplica acCmdEncryptDecryptDatabase acCmdImport acCmdLinkTables
Steps to Reproduce Behavior
- Start Microsoft Access 97.
- Open the sample database Northwind.mdb.
- Open a new, blank form in Design view.
Create a command button, and set the OnClick property to the following event procedure:
Sub Command0_Click() DoCmd.OutputTo acOutputTable, "Customers", acFormatTXT End Sub
- Open the form in Form view.
- Click the command button.
Note that Microsoft Access prompts you for the location of the output file name. - Choose a destination output file, and then click OK. This should successfully output the Customers table to the file you selected.
- Close and save the form as Form1.
- On the Tools menu, click Startup.
- In the Startup dialog box, select the Form1 form from the Display Form combo box, and then click OK.
- Close the database.
- Use the Setup Wizard to create disk images for the Northwind database. Be sure to select Northwind.mdb as the application's main file, and create a shortcut that uses the Run-time option to open Northwind.mdb.
- Install the application on a computer that has never had the retail version of Microsoft Access 97 installed.
- Start the application. When the startup form is displayed, click the command button.
Note that you receive the message "The OutputTo action was canceled," and then the application terminates.
REFERENCES
For more information about the OutputTo method, search the Help Index for "OutputTo method," or ask the Microsoft Access 97 Office Assistant.
For more information about the RunCommand method, search the Help Index for "RunCommand method," or ask the Microsoft Access 97 Office Assistant.
For more information about the Common Dialog ActiveX control, search the Help Index for "CommonDialog control," or ask the Microsoft Access 97 Office Assistant.
Additional query words: prb ode
Keywords: kbprb KB173334