vba

G

Guest

I have some queries that I use to make calculus and I’m trying to make those
queries run in a set up order, but I’m having some problems. I set up a table
with the name and the order of the queries. I want and wrote the flowing code
in VBA.
Private Sub cmdRunQueries_Click()
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim rs As DAO.Recordset
Dim strSQL As String
On Error GoTo Proc_Error
Set db = CurrentDb
strSQL = "SELECT QueryName FROM CalcQueries ORDER BY Seq;"
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.MoveFirst
Do Until rs.EOF
Set qd = db.QueryDefs(rs!QueryName) ' get the query name to execute
qd.Execute , dbFailOnError
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Proc_Exit: Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in cmdRunQueries_Click:" _
& vbCrLf & Err.Description
Resume Proc_Exit
End Sub

When I run the code in VBA it says that there is an error, but I can’t find
out what it is
 
D

Douglas J Steele

So exactly what appears on the Message Box if not error details?

I assume that the queries are action queries (INSERT INTO, DELETE, UPDATE):
you cannot run SELECT queries this way.
 
G

Guest

Says that the stament is wrong, and show the first line in yelow
(My vba is in portuguese I hope that is the right translation on what says)
The action does not start runing
the queries are Append queries
"Douglas J Steele" escreveu:
 
D

Douglas J Steele

What's "the first line"? The declaration Dim db As DAO.Database?

If so, do you have a reference set to DAO? (by default, Access 2000 and 2002
don't )
 
G

Guest

the first line that is righlight is this one
Private Sub cmdRunQueries_Click()
I don't really vba, some one send me this code any how too set it up, I did
that was told me to do, but every time I ser up to run when I click in a
comtrol says too me that access could not fins de macro. The code is save in
the vba on the form just like it was send too me. And the table with the name
and order of the queries has the same name I was told to put.
After I the code didn't work in the form I tried to put in a module and run
it too see if works and that when I saw the message I was telling you about.
I how I got something wrong in the way but I can't find it

"Douglas J Steele" escreveu:
 
D

Douglas J Steele

Private Sub cmdRunQueries_Click() implies that this code needs to be in the
code associated with a form, that the form in question has to have a command
button on it named cmdRunQueries, and that you've set the Click property for
the cmdRunQueries command button to [Event Procedure].

If that isn't the situation you have right now, try renaming the procedure
to simply Sub RunQueries(), and then you can invoke the routine using Call
RunQueries()
 
G

Guest

I think I finally getting somewhere, I set it up as you told me and right
after I click the button the vba page open up. It tried to run the code but
could not it says there is an error just like the one I told you before. The
error number is the 450. The parts underline are the same that vba highlight
when I execute the procedure. The translation of the error is something like
that—n° of arguments incorrect or property attribution invalidly. At lest the
vba is tring too run when is suppose to.
---Private Sub cmdRunQueries_Click()--- (this part)
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim rs As DAO.Recordset
Dim strSQL As String
On Error GoTo Proc_Error
Set db = CurrentDb
strSQL = "SELECT QueryName FROM CalcQueries ORDER BY Seq;"
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.MoveFirst
Do Until rs.EOF
Set qd = db.QueryDefs(rs!QueryName) ' get the query name to execute
qd.---Execute--- , dbFailOnError (the word execute is also hightlight)
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Proc_Exit: Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in cmdRunQueries_Click:" _
& vbCrLf & Err.Description
Resume Proc_Exit
End Sub

Thanks in advance


"Douglas J Steele" escreveu:
Private Sub cmdRunQueries_Click() implies that this code needs to be in the
code associated with a form, that the form in question has to have a command
button on it named cmdRunQueries, and that you've set the Click property for
the cmdRunQueries command button to [Event Procedure].

If that isn't the situation you have right now, try renaming the procedure
to simply Sub RunQueries(), and then you can invoke the routine using Call
RunQueries()



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Felipe said:
the first line that is righlight is this one
Private Sub cmdRunQueries_Click()
I don't really vba, some one send me this code any how too set it up, I did
that was told me to do, but every time I ser up to run when I click in a
comtrol says too me that access could not fins de macro. The code is save in
the vba on the form just like it was send too me. And the table with the name
and order of the queries has the same name I was told to put.
After I the code didn't work in the form I tried to put in a module and run
it too see if works and that when I saw the message I was telling you about.
I how I got something wrong in the way but I can't find it

"Douglas J Steele" escreveu:
 
D

Douglas J Steele

Your translation of the error message was good: AccessError(450) returns
"Wrong number of arguments or invalid property assignment" in English

What's the value of rs!QueryName when the error occurs? Does a query by that
name actually exist? Is the query expecting parameters?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Felipe said:
I think I finally getting somewhere, I set it up as you told me and right
after I click the button the vba page open up. It tried to run the code but
could not it says there is an error just like the one I told you before. The
error number is the 450. The parts underline are the same that vba highlight
when I execute the procedure. The translation of the error is something like
that-n° of arguments incorrect or property attribution invalidly. At lest the
vba is tring too run when is suppose to.
---Private Sub cmdRunQueries_Click()--- (this part)
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim rs As DAO.Recordset
Dim strSQL As String
On Error GoTo Proc_Error
Set db = CurrentDb
strSQL = "SELECT QueryName FROM CalcQueries ORDER BY Seq;"
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.MoveFirst
Do Until rs.EOF
Set qd = db.QueryDefs(rs!QueryName) ' get the query name to execute
qd.---Execute--- , dbFailOnError (the word execute is also hightlight)
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Proc_Exit: Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in cmdRunQueries_Click:" _
& vbCrLf & Err.Description
Resume Proc_Exit
End Sub

Thanks in advance


"Douglas J Steele" escreveu:
Private Sub cmdRunQueries_Click() implies that this code needs to be in the
code associated with a form, that the form in question has to have a command
button on it named cmdRunQueries, and that you've set the Click property for
the cmdRunQueries command button to [Event Procedure].

If that isn't the situation you have right now, try renaming the procedure
to simply Sub RunQueries(), and then you can invoke the routine using Call
RunQueries()
 
G

Guest

The names of the queries are correct, I double check. They have parameter.
Avery time I run any of the queries I have to put in the Id number, that is
call [n° da obra]
I don't know what you neam by the value of rs. PS I don't know what is RS

"Douglas J Steele" escreveu:
Your translation of the error message was good: AccessError(450) returns
"Wrong number of arguments or invalid property assignment" in English

What's the value of rs!QueryName when the error occurs? Does a query by that
name actually exist? Is the query expecting parameters?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Felipe said:
I think I finally getting somewhere, I set it up as you told me and right
after I click the button the vba page open up. It tried to run the code but
could not it says there is an error just like the one I told you before. The
error number is the 450. The parts underline are the same that vba highlight
when I execute the procedure. The translation of the error is something like
that-n° of arguments incorrect or property attribution invalidly. At lest the
vba is tring too run when is suppose to.
---Private Sub cmdRunQueries_Click()--- (this part)
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim rs As DAO.Recordset
Dim strSQL As String
On Error GoTo Proc_Error
Set db = CurrentDb
strSQL = "SELECT QueryName FROM CalcQueries ORDER BY Seq;"
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.MoveFirst
Do Until rs.EOF
Set qd = db.QueryDefs(rs!QueryName) ' get the query name to execute
qd.---Execute--- , dbFailOnError (the word execute is also hightlight)
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Proc_Exit: Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in cmdRunQueries_Click:" _
& vbCrLf & Err.Description
Resume Proc_Exit
End Sub

Thanks in advance


"Douglas J Steele" escreveu:
Private Sub cmdRunQueries_Click() implies that this code needs to be in the
code associated with a form, that the form in question has to have a command
button on it named cmdRunQueries, and that you've set the Click property for
the cmdRunQueries command button to [Event Procedure].

If that isn't the situation you have right now, try renaming the procedure
to simply Sub RunQueries(), and then you can invoke the routine using Call
RunQueries()
 
D

Douglas J Steele

Actually, I didn't mention anything about "the value of rs". I asked about
the value of rs!QueryName: in other words, are you getting the name of a
legitimate query when you refer to rs!QueryName.

However, AFAIK, you can't use parameter queries this way: you need to
provide the value of the parameter before you .Execute.

Do Until rs.EOF
Set qd = db.QueryDefs(rs!QueryName) ' get the query name to execute
qd.Parameters("n° da obra") = Value
qd.Execute, dbFailOnError
rs.MoveNext
Loop




--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Felipe said:
The names of the queries are correct, I double check. They have parameter.
Avery time I run any of the queries I have to put in the Id number, that is
call [n° da obra]
I don't know what you neam by the value of rs. PS I don't know what is RS

"Douglas J Steele" escreveu:
Your translation of the error message was good: AccessError(450) returns
"Wrong number of arguments or invalid property assignment" in English

What's the value of rs!QueryName when the error occurs? Does a query by that
name actually exist? Is the query expecting parameters?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Felipe said:
I think I finally getting somewhere, I set it up as you told me and right
after I click the button the vba page open up. It tried to run the
code
but
could not it says there is an error just like the one I told you
before.
The
error number is the 450. The parts underline are the same that vba highlight
when I execute the procedure. The translation of the error is
something
like
that-n° of arguments incorrect or property attribution invalidly. At
lest
the
vba is tring too run when is suppose to.
---Private Sub cmdRunQueries_Click()--- (this part)
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim rs As DAO.Recordset
Dim strSQL As String
On Error GoTo Proc_Error
Set db = CurrentDb
strSQL = "SELECT QueryName FROM CalcQueries ORDER BY Seq;"
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.MoveFirst
Do Until rs.EOF
Set qd = db.QueryDefs(rs!QueryName) ' get the query name to execute
qd.---Execute--- , dbFailOnError (the word execute is also hightlight)
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Proc_Exit: Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in cmdRunQueries_Click:" _
& vbCrLf & Err.Description
Resume Proc_Exit
End Sub

Thanks in advance


"Douglas J Steele" escreveu:

Private Sub cmdRunQueries_Click() implies that this code needs to
be in
the
code associated with a form, that the form in question has to have a command
button on it named cmdRunQueries, and that you've set the Click
property
for
the cmdRunQueries command button to [Event Procedure].

If that isn't the situation you have right now, try renaming the procedure
to simply Sub RunQueries(), and then you can invoke the routine
using
Call
RunQueries()
 
G

Guest

well I don't know any more what to do, I tried to take out all de parameters
a see if would work, but still showing the same message, than I tried too
replace with the code you send me and the same massage still coming up. I'm
quite sure I need a new way of doing that. The thing is I have lots of
calculations and got so big that I had to you several queries. That’s
happened because my database is all about keeping the results of those
calculation, but to get all right I need to do them in the right order. I
have 12 queries that make those calculations and save them in a new line on a
predetermined table. I have the same thing in a spreadsheet but the company
was getting big and things was getting lost once every time I needed the
number for my business a new spreadsheet was made, so I did all in access.
after a long journey tiring to make work I did it .all the calculus are store
right in the right place, but it is kind bad having to run all these queries
in the right order, so what I really need is something that do that for me in
just a click, but that is getting quite hard. I hope with this description
you can help me a little more
thanks
"Douglas J Steele" escreveu:
Actually, I didn't mention anything about "the value of rs". I asked about
the value of rs!QueryName: in other words, are you getting the name of a
legitimate query when you refer to rs!QueryName.

However, AFAIK, you can't use parameter queries this way: you need to
provide the value of the parameter before you .Execute.

Do Until rs.EOF
Set qd = db.QueryDefs(rs!QueryName) ' get the query name to execute
qd.Parameters("n° da obra") = Value
qd.Execute, dbFailOnError
rs.MoveNext
Loop




--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Felipe said:
The names of the queries are correct, I double check. They have parameter.
Avery time I run any of the queries I have to put in the Id number, that is
call [n° da obra]
I don't know what you neam by the value of rs. PS I don't know what is RS

"Douglas J Steele" escreveu:
Your translation of the error message was good: AccessError(450) returns
"Wrong number of arguments or invalid property assignment" in English

What's the value of rs!QueryName when the error occurs? Does a query by that
name actually exist? Is the query expecting parameters?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I think I finally getting somewhere, I set it up as you told me and right
after I click the button the vba page open up. It tried to run the code
but
could not it says there is an error just like the one I told you before.
The
error number is the 450. The parts underline are the same that vba
highlight
when I execute the procedure. The translation of the error is something
like
that-n° of arguments incorrect or property attribution invalidly. At lest
the
vba is tring too run when is suppose to.
---Private Sub cmdRunQueries_Click()--- (this part)
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim rs As DAO.Recordset
Dim strSQL As String
On Error GoTo Proc_Error
Set db = CurrentDb
strSQL = "SELECT QueryName FROM CalcQueries ORDER BY Seq;"
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.MoveFirst
Do Until rs.EOF
Set qd = db.QueryDefs(rs!QueryName) ' get the query name to execute
qd.---Execute--- , dbFailOnError (the word execute is also hightlight)
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Proc_Exit: Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in cmdRunQueries_Click:" _
& vbCrLf & Err.Description
Resume Proc_Exit
End Sub

Thanks in advance


"Douglas J Steele" escreveu:

Private Sub cmdRunQueries_Click() implies that this code needs to be in
the
code associated with a form, that the form in question has to have a
command
button on it named cmdRunQueries, and that you've set the Click property
for
the cmdRunQueries command button to [Event Procedure].

If that isn't the situation you have right now, try renaming the
procedure
to simply Sub RunQueries(), and then you can invoke the routine using
Call
RunQueries()
 
G

Guest

well I don't know any more what to do, I tried to take out all de parameters
a see if would work, but still showing the same message, than I tried too
replace with the code you send me and the same massage still coming up. I'm
quite sure I need a new way of doing that. The thing is I have lots of
calculations and got so big that I had to you several queries. That’s
happened because my database is all about keeping the results of those
calculation, but to get all right I need to do them in the right order. I
have 12 queries that make those calculations and save them in a new line on a
predetermined table. I have the same thing in a spreadsheet but the company
was getting big and things was getting lost once every time I needed the
number for my business a new spreadsheet was made, so I did all in access.
after a long journey tiring to make work I did it .all the calculus are store
right in the right place, but it is kind bad having to run all these queries
in the right order, so what I really need is something that do that for me in
just a click, but that is getting quite hard. I hope with this description
you can help me a little more
thanks


"Douglas J Steele" escreveu:
Actually, I didn't mention anything about "the value of rs". I asked about
the value of rs!QueryName: in other words, are you getting the name of a
legitimate query when you refer to rs!QueryName.

However, AFAIK, you can't use parameter queries this way: you need to
provide the value of the parameter before you .Execute.

Do Until rs.EOF
Set qd = db.QueryDefs(rs!QueryName) ' get the query name to execute
qd.Parameters("n° da obra") = Value
qd.Execute, dbFailOnError
rs.MoveNext
Loop




--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Felipe said:
The names of the queries are correct, I double check. They have parameter.
Avery time I run any of the queries I have to put in the Id number, that is
call [n° da obra]
I don't know what you neam by the value of rs. PS I don't know what is RS

"Douglas J Steele" escreveu:
Your translation of the error message was good: AccessError(450) returns
"Wrong number of arguments or invalid property assignment" in English

What's the value of rs!QueryName when the error occurs? Does a query by that
name actually exist? Is the query expecting parameters?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I think I finally getting somewhere, I set it up as you told me and right
after I click the button the vba page open up. It tried to run the code
but
could not it says there is an error just like the one I told you before.
The
error number is the 450. The parts underline are the same that vba
highlight
when I execute the procedure. The translation of the error is something
like
that-n° of arguments incorrect or property attribution invalidly. At lest
the
vba is tring too run when is suppose to.
---Private Sub cmdRunQueries_Click()--- (this part)
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim rs As DAO.Recordset
Dim strSQL As String
On Error GoTo Proc_Error
Set db = CurrentDb
strSQL = "SELECT QueryName FROM CalcQueries ORDER BY Seq;"
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.MoveFirst
Do Until rs.EOF
Set qd = db.QueryDefs(rs!QueryName) ' get the query name to execute
qd.---Execute--- , dbFailOnError (the word execute is also hightlight)
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Proc_Exit: Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in cmdRunQueries_Click:" _
& vbCrLf & Err.Description
Resume Proc_Exit
End Sub

Thanks in advance


"Douglas J Steele" escreveu:

Private Sub cmdRunQueries_Click() implies that this code needs to be in
the
code associated with a form, that the form in question has to have a
command
button on it named cmdRunQueries, and that you've set the Click property
for
the cmdRunQueries command button to [Event Procedure].

If that isn't the situation you have right now, try renaming the
procedure
to simply Sub RunQueries(), and then you can invoke the routine using
Call
RunQueries()
 
D

Douglas J Steele

Just to ensure that you are getting the correct queryname, try changing your
code to:

Dim strQueryName As String

Do Until rs.EOF
strQueryName = rs!QueryName
MsgBox strQueryName & _
" (" & Len(strQueryName) & " characters long)"
Set qd = db.QueryDefs(strQueryName)
qd.Parameters("n° da obra") = Value
qd.Execute, dbFailOnError
rs.MoveNext
Loop

(the reason for the Len(strQueryName) is just in case there are special
characters in the string that you can't see: make sure the length is
appropriate for the query name)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Felipe said:
well I don't know any more what to do, I tried to take out all de parameters
a see if would work, but still showing the same message, than I tried too
replace with the code you send me and the same massage still coming up. I'm
quite sure I need a new way of doing that. The thing is I have lots of
calculations and got so big that I had to you several queries. That's
happened because my database is all about keeping the results of those
calculation, but to get all right I need to do them in the right order. I
have 12 queries that make those calculations and save them in a new line on a
predetermined table. I have the same thing in a spreadsheet but the company
was getting big and things was getting lost once every time I needed the
number for my business a new spreadsheet was made, so I did all in access.
after a long journey tiring to make work I did it .all the calculus are store
right in the right place, but it is kind bad having to run all these queries
in the right order, so what I really need is something that do that for me in
just a click, but that is getting quite hard. I hope with this description
you can help me a little more
thanks
"Douglas J Steele" escreveu:
Actually, I didn't mention anything about "the value of rs". I asked about
the value of rs!QueryName: in other words, are you getting the name of a
legitimate query when you refer to rs!QueryName.

However, AFAIK, you can't use parameter queries this way: you need to
provide the value of the parameter before you .Execute.

Do Until rs.EOF
Set qd = db.QueryDefs(rs!QueryName) ' get the query name to execute
qd.Parameters("n° da obra") = Value
qd.Execute, dbFailOnError
rs.MoveNext
Loop




--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Felipe said:
The names of the queries are correct, I double check. They have parameter.
Avery time I run any of the queries I have to put in the Id number,
that
is
call [n° da obra]
I don't know what you neam by the value of rs. PS I don't know what is RS

"Douglas J Steele" escreveu:

Your translation of the error message was good: AccessError(450) returns
"Wrong number of arguments or invalid property assignment" in English

What's the value of rs!QueryName when the error occurs? Does a query
by
that
name actually exist? Is the query expecting parameters?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I think I finally getting somewhere, I set it up as you told me
and
right
after I click the button the vba page open up. It tried to run the code
but
could not it says there is an error just like the one I told you before.
The
error number is the 450. The parts underline are the same that vba
highlight
when I execute the procedure. The translation of the error is something
like
that-n° of arguments incorrect or property attribution invalidly.
At
lest
the
vba is tring too run when is suppose to.
---Private Sub cmdRunQueries_Click()--- (this part)
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim rs As DAO.Recordset
Dim strSQL As String
On Error GoTo Proc_Error
Set db = CurrentDb
strSQL = "SELECT QueryName FROM CalcQueries ORDER BY Seq;"
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.MoveFirst
Do Until rs.EOF
Set qd = db.QueryDefs(rs!QueryName) ' get the query name to execute
qd.---Execute--- , dbFailOnError (the word execute is also hightlight)
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Proc_Exit: Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in cmdRunQueries_Click:" _
& vbCrLf & Err.Description
Resume Proc_Exit
End Sub

Thanks in advance


"Douglas J Steele" escreveu:

Private Sub cmdRunQueries_Click() implies that this code needs
to
be in
the
code associated with a form, that the form in question has to have a
command
button on it named cmdRunQueries, and that you've set the Click property
for
the cmdRunQueries command button to [Event Procedure].

If that isn't the situation you have right now, try renaming the
procedure
to simply Sub RunQueries(), and then you can invoke the routine using
Call
RunQueries()
 
G

Guest

Well I run the code you gave me and how shows that I have the error n° 424.
says that where an error in the execution time

"Douglas J Steele" escreveu:
Just to ensure that you are getting the correct queryname, try changing your
code to:

Dim strQueryName As String

Do Until rs.EOF
strQueryName = rs!QueryName
MsgBox strQueryName & _
" (" & Len(strQueryName) & " characters long)"
Set qd = db.QueryDefs(strQueryName)
qd.Parameters("n° da obra") = Value
qd.Execute, dbFailOnError
rs.MoveNext
Loop

(the reason for the Len(strQueryName) is just in case there are special
characters in the string that you can't see: make sure the length is
appropriate for the query name)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Felipe said:
well I don't know any more what to do, I tried to take out all de parameters
a see if would work, but still showing the same message, than I tried too
replace with the code you send me and the same massage still coming up. I'm
quite sure I need a new way of doing that. The thing is I have lots of
calculations and got so big that I had to you several queries. That's
happened because my database is all about keeping the results of those
calculation, but to get all right I need to do them in the right order. I
have 12 queries that make those calculations and save them in a new line on a
predetermined table. I have the same thing in a spreadsheet but the company
was getting big and things was getting lost once every time I needed the
number for my business a new spreadsheet was made, so I did all in access.
after a long journey tiring to make work I did it .all the calculus are store
right in the right place, but it is kind bad having to run all these queries
in the right order, so what I really need is something that do that for me in
just a click, but that is getting quite hard. I hope with this description
you can help me a little more
thanks
"Douglas J Steele" escreveu:
Actually, I didn't mention anything about "the value of rs". I asked about
the value of rs!QueryName: in other words, are you getting the name of a
legitimate query when you refer to rs!QueryName.

However, AFAIK, you can't use parameter queries this way: you need to
provide the value of the parameter before you .Execute.

Do Until rs.EOF
Set qd = db.QueryDefs(rs!QueryName) ' get the query name to execute
qd.Parameters("n° da obra") = Value
qd.Execute, dbFailOnError
rs.MoveNext
Loop




--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


The names of the queries are correct, I double check. They have parameter.
Avery time I run any of the queries I have to put in the Id number, that
is
call [n° da obra]
I don't know what you neam by the value of rs. PS I don't know what is RS

"Douglas J Steele" escreveu:

Your translation of the error message was good: AccessError(450) returns
"Wrong number of arguments or invalid property assignment" in English

What's the value of rs!QueryName when the error occurs? Does a query by
that
name actually exist? Is the query expecting parameters?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I think I finally getting somewhere, I set it up as you told me and
right
after I click the button the vba page open up. It tried to run the
code
but
could not it says there is an error just like the one I told you
before.
The
error number is the 450. The parts underline are the same that vba
highlight
when I execute the procedure. The translation of the error is
something
like
that-n° of arguments incorrect or property attribution invalidly. At
lest
the
vba is tring too run when is suppose to.
---Private Sub cmdRunQueries_Click()--- (this part)
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim rs As DAO.Recordset
Dim strSQL As String
On Error GoTo Proc_Error
Set db = CurrentDb
strSQL = "SELECT QueryName FROM CalcQueries ORDER BY Seq;"
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.MoveFirst
Do Until rs.EOF
Set qd = db.QueryDefs(rs!QueryName) ' get the query name to execute
qd.---Execute--- , dbFailOnError (the word execute is also hightlight)
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Proc_Exit: Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in cmdRunQueries_Click:" _
& vbCrLf & Err.Description
Resume Proc_Exit
End Sub

Thanks in advance


"Douglas J Steele" escreveu:

Private Sub cmdRunQueries_Click() implies that this code needs to
be in
the
code associated with a form, that the form in question has to have a
command
button on it named cmdRunQueries, and that you've set the Click
property
for
the cmdRunQueries command button to [Event Procedure].

If that isn't the situation you have right now, try renaming the
procedure
to simply Sub RunQueries(), and then you can invoke the routine
using
Call
RunQueries()
 
D

Douglas J Steele

Error 424 is "object not found". That implies to me that something's not
getting instantiated properly.

What's the exact code you're running?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Felipe said:
Well I run the code you gave me and how shows that I have the error n° 424.
says that where an error in the execution time

"Douglas J Steele" escreveu:
Just to ensure that you are getting the correct queryname, try changing your
code to:

Dim strQueryName As String

Do Until rs.EOF
strQueryName = rs!QueryName
MsgBox strQueryName & _
" (" & Len(strQueryName) & " characters long)"
Set qd = db.QueryDefs(strQueryName)
qd.Parameters("n° da obra") = Value
qd.Execute, dbFailOnError
rs.MoveNext
Loop

(the reason for the Len(strQueryName) is just in case there are special
characters in the string that you can't see: make sure the length is
appropriate for the query name)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Felipe said:
well I don't know any more what to do, I tried to take out all de parameters
a see if would work, but still showing the same message, than I tried too
replace with the code you send me and the same massage still coming
up.
I'm
quite sure I need a new way of doing that. The thing is I have lots of
calculations and got so big that I had to you several queries. That's
happened because my database is all about keeping the results of those
calculation, but to get all right I need to do them in the right order. I
have 12 queries that make those calculations and save them in a new
line
on a
predetermined table. I have the same thing in a spreadsheet but the company
was getting big and things was getting lost once every time I needed the
number for my business a new spreadsheet was made, so I did all in access.
after a long journey tiring to make work I did it .all the calculus
are
store
right in the right place, but it is kind bad having to run all these queries
in the right order, so what I really need is something that do that
for me
in
just a click, but that is getting quite hard. I hope with this description
you can help me a little more
thanks
"Douglas J Steele" escreveu:

Actually, I didn't mention anything about "the value of rs". I asked about
the value of rs!QueryName: in other words, are you getting the name of a
legitimate query when you refer to rs!QueryName.

However, AFAIK, you can't use parameter queries this way: you need to
provide the value of the parameter before you .Execute.

Do Until rs.EOF
Set qd = db.QueryDefs(rs!QueryName) ' get the query name to execute
qd.Parameters("n° da obra") = Value
qd.Execute, dbFailOnError
rs.MoveNext
Loop




--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


The names of the queries are correct, I double check. They have parameter.
Avery time I run any of the queries I have to put in the Id
number,
that
is
call [n° da obra]
I don't know what you neam by the value of rs. PS I don't know
what is
RS
"Douglas J Steele" escreveu:

Your translation of the error message was good: AccessError(450) returns
"Wrong number of arguments or invalid property assignment" in English

What's the value of rs!QueryName when the error occurs? Does a
query
by
that
name actually exist? Is the query expecting parameters?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I think I finally getting somewhere, I set it up as you told
me
and
right
after I click the button the vba page open up. It tried to run the
code
but
could not it says there is an error just like the one I told you
before.
The
error number is the 450. The parts underline are the same that vba
highlight
when I execute the procedure. The translation of the error is
something
like
that-n° of arguments incorrect or property attribution
invalidly.
At
lest
the
vba is tring too run when is suppose to.
---Private Sub cmdRunQueries_Click()--- (this part)
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim rs As DAO.Recordset
Dim strSQL As String
On Error GoTo Proc_Error
Set db = CurrentDb
strSQL = "SELECT QueryName FROM CalcQueries ORDER BY Seq;"
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.MoveFirst
Do Until rs.EOF
Set qd = db.QueryDefs(rs!QueryName) ' get the query name to execute
qd.---Execute--- , dbFailOnError (the word execute is also hightlight)
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Proc_Exit: Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in cmdRunQueries_Click:" _
& vbCrLf & Err.Description
Resume Proc_Exit
End Sub

Thanks in advance


"Douglas J Steele" escreveu:

Private Sub cmdRunQueries_Click() implies that this code
needs
to
be in
the
code associated with a form, that the form in question has
to
have a
command
button on it named cmdRunQueries, and that you've set the Click
property
for
the cmdRunQueries command button to [Event Procedure].

If that isn't the situation you have right now, try renaming the
procedure
to simply Sub RunQueries(), and then you can invoke the routine
using
Call
RunQueries()
 

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