VBA SQL query

Gregorys05

Board Regular
Joined
Sep 24, 2008
Messages
217
Hi All
I have the below code, when i run it in an access query, it works but when run in VBA i get the following error:

Run Time Error 3061
Too Few Paramaters Expected 1

Any Ideas??

Code:
Private Sub Replace_Click()
Dim DB As Database
Set DB = CurrentDb()
Dim QDF As QueryDef
Dim SQL As String
Set QDF = DB.CreateQueryDef("", "DELETE tblreplace.*, tblreplace.ReplacePath " & _
"FROM tblreplace WHERE (((tblreplace.ReplacePath)= Forms!Replace!NewImageaddress));")
QDF.Execute
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Another possibility is that you could have to evealuate the parameters first. Depends on the query; often it's not necessary but see how you go...
Code:
Private Sub Replace_Click()
  Dim DB As DAO.Database
  Dim QDF As DAO.QueryDef
  Dim PRM As DAO.Parameter
  Dim SQL As String
  Set DB = CurrentDb()
  Set QDF = DB.CreateQueryDef("", "DELETE tblreplace.*, tblreplace.ReplacePath " & _
    "FROM tblreplace WHERE (((tblreplace.ReplacePath)= Forms!Replace!NewImageaddress));")
  For Each PRM In QDF.Parameters
    PRM.Value = Eval(PRM.Name)
  Next PRM
  QDF.Execute
End Sub

Note: You should always be explicit about whether you are using DAO or ADO recordsets. I have included the DAO qualification.

Denis
 
Upvote 0

Forum statistics

Threads
1,224,570
Messages
6,179,610
Members
452,931
Latest member
The Monk

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top