DAO select

W

wAyne

I'm trying to go through a table one record at a time.
here is my code

Dim str_sqltext As String
Dim con1 As DAO.Database
Dim rst_Estim As DAO.Recordset

str_sqltext = "SELECT Estim.PartNo, Estim.Desc, Estim.ProdCode " _
& "FROM Estim " _
& "WHERE Estim.ProdCode Like " & Chr(34) & "FG*" & Chr(34) _
& ";"


Set con1 = CurrentDb
Set rst_Estim = con1.OpenRecordset(str_sqltext)

If Not rst_Estim.EOF Then
rst_Estim.MoveFirst

Do While Not rst_Estim.EOF
str_PartNo = rst_Estim!PartNo
Call Materials_0_Detail

rst_Estim.MoveNext
Loop
Else
MsgBox "No Finished goods parts???"
End If


I swear I have done this before with no problems -- now I get the following
error:

Run Time Error 3061
Too Few parameters - expected 1

This happens on the Set rst_Estim = con1.OpenRecordset(str_sqltext) command.

The only thing I can think of that is different from other times I have done
this is the table "Estim" is a linked table.

thanks
for your help
wAyne
 
D

Douglas J. Steele

Make sure you haven't made a typo on any of the names in your Select query.
 
D

DaveT

One way to debug SQL statements in VBA is to use Debug.Print to print the SQL
generated from VBA. (In you case, after str_sqltext put a line with
Debug.Print str_sqltext).

If you know the procedure will crash for sure, go ahead and temporarily put
Exit Function (or Exit Sub) afte the Debug.Print line.

Call the procedure, then cut and paste the sql statement from the Immediate
window into a new SQL query using the query designer interface.

You can debug the sql statement there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top