please help
when i use the following code with Query have criteria
too few parameters. expected 1 Error
the code
Code Tags Added by UG
Please use Code Tags when posting VBA Code
Please feel free to Remove this Comment
https://www.access-programmers.co.u...e-use-code-tags-when-posting-vba-code.240420/
when i use the following code with Query have criteria
too few parameters. expected 1 Error
the code
Code Tags Added by UG
Please use Code Tags when posting VBA Code
Please feel free to Remove this Comment
https://www.access-programmers.co.u...e-use-code-tags-when-posting-vba-code.240420/
Code:
Public Sub DataToText(ByVal strTable As String, Optional ByVal strOutput As String = "", _
Optional ByVal strDelimiter As String = "", _
Optional ByVal bolExtaSpaceAbove As Boolean = False)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim outFile As Integer
Dim i As Integer
Dim LineOfText As String
On Error GoTo ErrHandler
DoCmd.Hourglass True
If strOutput = "" Then strOutput = CurrentProject.Path & "\Text.txt"
If strDelimiter = "" Then strDelimiter = Chr(9)
If Dir(strOutput) <> "" Then Kill (strOutput)
outFile = FreeFile
Open strOutput For Output As #outFile
Set db = CurrentDb
Set rs = CurrentDb.OpenRecordset(strTable, dbOpenSnapshot)
With rs
If Not (.BOF And .EOF) Then
.MoveFirst
If bolExtaSpaceAbove Then
Print #outFile, ""
End If
'if you want column headers, uncomment the following 5 lines of code
For i = 0 To .Fields.Count - 1
LineOfText = LineOfText & .Fields(i).Name & strDelimiter
Next i
LineOfText = Left(LineOfText, InStrRev(LineOfText, strDelimiter) - 1)
Print #outFile, LineOfText
'loop through records
Do While Not .EOF
LineOfText = ""
'build up line of text
For i = 0 To .Fields.Count - 1
LineOfText = LineOfText & Nz(.Fields(i)) & strDelimiter
Next i
LineOfText = Left(LineOfText, InStrRev(LineOfText, strDelimiter) - 1)
'write line of text to file
Print #outFile, LineOfText
.MoveNext
Loop
End If
End With
Resume_Here:
If Not rs Is Nothing Then rs.Close: Set rs = Nothing
If Not db Is Nothing Then Set db = Nothing
If outFile > 0 Then Close #outFile
DoCmd.Hourglass False
Exit Sub
ErrHandler:
DoCmd.Hourglass False
If Err.Number = 70 Then
MsgBox "Error: " & Err.Number & vbCrLf & vbCrLf & _
"Cannot create " & strOutput & "." & vbCrLf & _
"Make sure you have sufficient right."
Else
MsgBox Err.Number & ": " & Err.Description
End If
Resume Resume_Here
Resume
End Sub
Public Function SpecialFolderPath1(strFolder As String) As String
' Find out the path to the passed special folder. User on of the following arguments:
' Options For specical folders
' AllUsersDesktop
' AllUsersStartMenu
' AllUsersPrograms
' AllUsersStartup
' Desktop
' Favorites
' Fonts
' MyDocuments
' NetHood
' PrintHood
' Programs
' Recent
' SendTo
' StartMenu
' Startup
' Templates
On Error GoTo ErrorHandler
'Create a Windows Script Host Object
Dim objWSHShell As Object
Set objWSHShell = CreateObject("WScript.Shell")
'Retrieve path
SpecialFolderPath1 = objWSHShell.specialfolders(strFolder & "")
CleanUp:
' Clean up
Set objWSHShell = Nothing
Exit Function
'**************************************
'* Error Handler
'**************************************
ErrorHandler:
MsgBox "Error finding " & strFolder, vbCritical + vbOKOnly, "Error"
Resume CleanUp
End Function
Last edited by a moderator: