Error 3061 (Too few parameters, Expected 1) ???

A

Alp Bekisoglu

It might be an obvious one but... why do I get this error on clicking the
"Command0" button? Any help is much appreciated.

TIA

Alp

Code:
Private Sub Command0_Click()
DAOQuery
End Sub

Function DAOQuery() As Long
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strQry As String, tablo As String, yr As Long
tablo = Me!nm
yr = Me!ygir

On Error GoTo DAOQuery_Error

Set dbs = CurrentDb()
strQry = "SELECT fm As basla, to As son, first As ilk, tax As vergi, next
As sonraki, rate As oran FROM " & tablo & " WHERE [" & tablo & "].from<=" &
yr & " And [" & tablo & "].to>=" & yr
' strQry = "SELECT Count(year) As numRecords FROM " & tablo 'SQL
Set rst = dbs.OpenRecordset(strQry)
Me!Text6 = strQry
With rst
DAOQuery = !vergi + ((yr - !ilk) * !oran)
Me!Text8 = DAOQuery
Me!bas = !basla
Me!son = !son
Me!first = !ilk
Me!tax = !vergi
Me!sonra = !sonraki
Me!voran = !oran
'.Close 'close the DAO recordset
End With

Set rst = Nothing
Set dbs = Nothing

On Error GoTo 0
Exit Function

DAOQuery_Error:

MsgBox "Error " & Err.Number & " (" & Err.description & ")", vbCritical

End Function
 
W

Wayne Morgan

Where is the function located? Is it in the form's module or a standard
module? If the latter, Me won't work. Also, if the latter, it would need to
be a Public Function.

You have the table name surround in brackets part of the time, but not all
of the time. If there is a space in the name the brackets will need to be
there all of the time, if there isn't a space then it won't matter.

You have commented out the .Close statement, it is actually a good idea to
Close the recordset.

Some of the names you have picked for fields I wouldn't use in an English
database because some appear to be reserved words, this might not be the
case in your version though.

Have you stepped through the code to find out which line is generating the
error?
DAOQuery = !vergi + ((yr - !ilk) * !oran)
Me!Text8 = DAOQuery
I would probably assign the calculation to Me!Text8 then assign Me!Text8 to
DAOQuery, but it's probably just me being picky about the way it looks. I
don't know that what you have won't work.

If you do get an error, you go to your error handler, pop-up a message, then
fall out the bottom of the procedure. You don't go back and clean up your
variables. May I suggest the following additions?
CleanUp:
Set rst = Nothing
Set dbs = Nothing

On Error GoTo 0
Exit Function

DAOQuery_Error:

MsgBox "Error " & Err.Number & " (" & Err.description & ")", vbCritical Resume CleanUp

End Function


--
Wayne Morgan
Microsoft Access MVP


Alp Bekisoglu said:
It might be an obvious one but... why do I get this error on clicking the
"Command0" button? Any help is much appreciated.

TIA

Alp

Code:
Private Sub Command0_Click()
DAOQuery
End Sub

Function DAOQuery() As Long
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strQry As String, tablo As String, yr As Long
tablo = Me!nm
yr = Me!ygir

On Error GoTo DAOQuery_Error

Set dbs = CurrentDb()
strQry = "SELECT fm As basla, to As son, first As ilk, tax As vergi, next
As sonraki, rate As oran FROM " & tablo & " WHERE [" & tablo & "].from<=" &
yr & " And [" & tablo & "].to>=" & yr
' strQry = "SELECT Count(year) As numRecords FROM " & tablo 'SQL
Set rst = dbs.OpenRecordset(strQry)
Me!Text6 = strQry
With rst
DAOQuery = !vergi + ((yr - !ilk) * !oran)
Me!Text8 = DAOQuery
Me!bas = !basla
Me!son = !son
Me!first = !ilk
Me!tax = !vergi
Me!sonra = !sonraki
Me!voran = !oran
'.Close 'close the DAO recordset
End With

Set rst = Nothing
Set dbs = Nothing

On Error GoTo 0
Exit Function

DAOQuery_Error:

MsgBox "Error " & Err.Number & " (" & Err.description & ")", vbCritical

End Function
 
A

Alp Bekisoglu

Hi Wayne and thank you for the suggestions. I did apply them.

This is behind a form, for now. I am trying it so some of the assignings
will not be there that is IF I'm ever able to get what I need from the code
correctly.

The brackets came into the picture when I got an error (missing operand) and
putting them there did away with the problem. Not sure why it came up
anyway. The name of the table(s) I am refering to are like 2004, 2003 etc so
no spaces definitely.

Actually this is in effort to solve a problem that has haunted me for the
past few weeks now. I have another post (well, sort of a lost hope type of
post but...) on this issue. Take a look at that if you have the time. Title
is "About to give up.... on coding a query".

All in all, instead of using a static query (that is working perfectly) I
need to use code since the source file will change over years. Thus I'm
stuck with continuous trials (and of course failures till now).

Is there any hope?

Sincerly,

Alp
P.S.: Some of the variable names are in Turkish actually. This was one way
of avoiding conflicts with the English based reserved names.

Wayne Morgan said:
Where is the function located? Is it in the form's module or a standard
module? If the latter, Me won't work. Also, if the latter, it would need to
be a Public Function.

You have the table name surround in brackets part of the time, but not all
of the time. If there is a space in the name the brackets will need to be
there all of the time, if there isn't a space then it won't matter.

You have commented out the .Close statement, it is actually a good idea to
Close the recordset.

Some of the names you have picked for fields I wouldn't use in an English
database because some appear to be reserved words, this might not be the
case in your version though.

Have you stepped through the code to find out which line is generating the
error?
DAOQuery = !vergi + ((yr - !ilk) * !oran)
Me!Text8 = DAOQuery
I would probably assign the calculation to Me!Text8 then assign Me!Text8 to
DAOQuery, but it's probably just me being picky about the way it looks. I
don't know that what you have won't work.

If you do get an error, you go to your error handler, pop-up a message, then
fall out the bottom of the procedure. You don't go back and clean up your
variables. May I suggest the following additions?
CleanUp:
Set rst = Nothing
Set dbs = Nothing

On Error GoTo 0
Exit Function

DAOQuery_Error:

MsgBox "Error " & Err.Number & " (" & Err.description & ")",
vbCritical
Resume CleanUp
End Function


--
Wayne Morgan
Microsoft Access MVP


Alp Bekisoglu said:
It might be an obvious one but... why do I get this error on clicking the
"Command0" button? Any help is much appreciated.

TIA

Alp

Code:
Private Sub Command0_Click()
DAOQuery
End Sub

Function DAOQuery() As Long
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strQry As String, tablo As String, yr As Long
tablo = Me!nm
yr = Me!ygir

On Error GoTo DAOQuery_Error

Set dbs = CurrentDb()
strQry = "SELECT fm As basla, to As son, first As ilk, tax As vergi, next
As sonraki, rate As oran FROM " & tablo & " WHERE [" & tablo &
"].from<="
&
yr & " And [" & tablo & "].to>=" & yr
' strQry = "SELECT Count(year) As numRecords FROM " & tablo 'SQL
Set rst = dbs.OpenRecordset(strQry)
Me!Text6 = strQry
With rst
DAOQuery = !vergi + ((yr - !ilk) * !oran)
Me!Text8 = DAOQuery
Me!bas = !basla
Me!son = !son
Me!first = !ilk
Me!tax = !vergi
Me!sonra = !sonraki
Me!voran = !oran
'.Close 'close the DAO recordset
End With

Set rst = Nothing
Set dbs = Nothing

On Error GoTo 0
Exit Function

DAOQuery_Error:

MsgBox "Error " & Err.Number & " (" & Err.description & ")", vbCritical

End Function
 

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