Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Parameters from a Access Form to VBA

Status
Not open for further replies.

fryguy5049

Technical User
Apr 20, 2004
24
US
I am using Access 2000 with an Access db,forms,querys,modules.
I have a command button on a form that executes VB code/module. The form also has 2 text boxes to use as date parameters(begin & end date) in the query.
How do I get those parameters into the VB code?
I get the error "Run time error 3061, too few parameters, expected 2"
I have seen many other threads concerning this issue but they are not my exact situation and my inexperience in VB limits me from adpating the solutions. Could you look at this code and suggest a solution. Thanks!
Code:
Sub ExportTextFile()

Dim db As Database, rst As DAO.Recordset
Dim qdf As QueryDef
Dim Directory As String
Dim MyString As String, strSQL As String
Dim strPARAM As Parameter

      
Set db = CurrentDb



Directory = (Mid(db.Name, 1, Len(db.Name) - Len(Dir(db.Name))))

Open Directory & "\TestOutput.txt" For Output As #1

Set rst = db.OpenRecordset("FDR batch xport")

Print #1, "HDAJFEBB" & Format(Date, "mmddyy") & Format(Time, "hhmmss")
rst.MoveFirst
Do While Not rst.EOF
    MyString = rst!acct
    Print #1, MyString
    rst.MoveNext
    
Loop
Print #1, "TLAJFEBB"

ExportTextFile_Exit:
' Close text file.
    Close #1
    rst.Close
    Set db = Nothing
    Exit Sub



End Sub
 
...
Dim prm As DAO.Parameter
Set db = CurrentDb
Set qdf = db.QueryDefs("FDR batch xport")
For Each prm In qdf.Parameters
prm = Eval(prm.Name)
Next prm
...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I get the same error as mentioned above. Does this code need to be inserted in a specific spot? Thanks
 
OOps forgot to mention the following:
Replace this:
Set rst = db.OpenRecordset("FDR batch xport")
By this:
Set rst = qdf.OpenRecordset("FDR batch xport")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks. I believe that cleared up that problem. Now I get the error "Run-Time error 3421: Data Type conversion error".
Any clues to what causes this error? Thanks again for working with me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top