Referencing controls

F

Fay Yocum

1) I had an article a year ago about referencing different controls and
can't find it now. Does any one remember the link to the article that
explains how to reference controls.?

2) My main problem is as follows. On my main form "frmReports" there is a
subform "fsubDepartsReqTel" which has a control "chkRequested". The subform
is a datasheet which lists departments that is used to select which
departments should be reported on. I don't know if I approached it right but
I also put a field in the department table for requested. I need to make
sure that there is a way to set the value in the table to False. I figured a
button would be the appropriate approach. But I haven't figured out the on
click event. Any help would be appreciated. Thank you.

Using Access03

Fay
 
F

Fay Yocum

Good morning Allen thank you for your help. I used the strSql code. It gets
to the last line and gives me the Run-time error "3601' Too few parameters.
Expected 1.

Fay
 
A

Allen Browne

The article may have been:
Referring to Controls on a Subform
at:
http://allenbrowne.com/casu-04.html

For the example you give, try:
Forms!frmReports!fsubDepartsReqTel.Form!chkRequested


If you have a button on the subform, you could set chkRequeted to no in the
current row with:
Private Sub cmdSetNo_Click()
Me.chkRequested = False
End Sub

If you wanted to change all records to No in Table1:
Dim strSql as String
strSql = "UPDATE Table1 SET chkRequested = False WHERE chkRequested =
True;"
dbEngine(0)(0).Execute strSql, dbFailOnError
 
F

Fay Yocum

I double checked that the Table 1 was changed to tblDepartments and that
chkRequested was correct. They were I still get the
"Run-time error "3601' Too few parameters. Expected 1" error message.

Message if I do the Forms!.... that you indicated earlier I get "Run-time
error "3601' Too few parameters. Expected 2" error message.

Thank you Allen. Fay


Allen Browne said:
Access asks for parameters if it does not understand one of the names your
table.

Substitute the name of your table for Table1.
Substitute the name of your yes/no field for chkRequested.
If your names have spaces in them, enclose them in square brackets, e.g.
[Table 1]

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Fay Yocum said:
Good morning Allen thank you for your help. I used the strSql code. It
gets to the last line and gives me the Run-time error "3601' Too few
parameters. Expected 1.

Fay
 
A

Allen Browne

Access asks for parameters if it does not understand one of the names your
table.

Substitute the name of your table for Table1.
Substitute the name of your yes/no field for chkRequested.
If your names have spaces in them, enclose them in square brackets, e.g.
[Table 1]
 
A

Allen Browne

Fay, if you are trying to execute a query that has a parameter, you need to
supply the parameter.

The simplest solution is to build up the string to execute, e.g.:
strSql = "UPDATE Table1 SET Field1 = 2 WHERE Field3 = " &
Forms!Form1!Text0 & ";"

Alternatively, you can supply the parameter programmatically like this:
Dim qdf As DAO.QueryDef
Set qdf = dbEngine(0)(0).QueryDefs("Query1")
qdf.Parameters("[Forms]![Form1]![Text0]") = [Forms]![Form1]![Text0]
qdf.Execute ...

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Fay Yocum said:
I double checked that the Table 1 was changed to tblDepartments and that
chkRequested was correct. They were I still get the
"Run-time error "3601' Too few parameters. Expected 1" error message.

Message if I do the Forms!.... that you indicated earlier I get "Run-time
error "3601' Too few parameters. Expected 2" error message.

Thank you Allen. Fay


Allen Browne said:
Access asks for parameters if it does not understand one of the names
your table.

Substitute the name of your table for Table1.
Substitute the name of your yes/no field for chkRequested.
If your names have spaces in them, enclose them in square brackets, e.g.
[Table 1]

Fay Yocum said:
Good morning Allen thank you for your help. I used the strSql code. It
gets to the last line and gives me the Run-time error "3601' Too few
parameters. Expected 1.

Fay


The article may have been:
Referring to Controls on a Subform
at:
http://allenbrowne.com/casu-04.html

For the example you give, try:
Forms!frmReports!fsubDepartsReqTel.Form!chkRequested


If you have a button on the subform, you could set chkRequeted to no in
the current row with:
Private Sub cmdSetNo_Click()
Me.chkRequested = False
End Sub

If you wanted to change all records to No in Table1:
Dim strSql as String
strSql = "UPDATE Table1 SET chkRequested = False WHERE chkRequested
= True;"
dbEngine(0)(0).Execute strSql, dbFailOnError

1) I had an article a year ago about referencing different controls
and can't find it now. Does any one remember the link to the article
that explains how to reference controls.?

2) My main problem is as follows. On my main form "frmReports" there
is a subform "fsubDepartsReqTel" which has a control "chkRequested".
The subform is a datasheet which lists departments that is used to
select which departments should be reported on. I don't know if I
approached it right but I also put a field in the department table for
requested. I need to make sure that there is a way to set the value in
the table to False. I figured a button would be the appropriate
approach. But I haven't figured out the on click event. Any help would
be appreciated. Thank you.

Using Access03
 
F

Fay Yocum

You got me thinking. So I created an Update query and run that with the
button. I have no skills with SQL. Thanks for the help. Fay

Allen Browne said:
Fay, if you are trying to execute a query that has a parameter, you need
to supply the parameter.

The simplest solution is to build up the string to execute, e.g.:
strSql = "UPDATE Table1 SET Field1 = 2 WHERE Field3 = " &
Forms!Form1!Text0 & ";"

Alternatively, you can supply the parameter programmatically like this:
Dim qdf As DAO.QueryDef
Set qdf = dbEngine(0)(0).QueryDefs("Query1")
qdf.Parameters("[Forms]![Form1]![Text0]") = [Forms]![Form1]![Text0]
qdf.Execute ...

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Fay Yocum said:
I double checked that the Table 1 was changed to tblDepartments and that
chkRequested was correct. They were I still get the
"Run-time error "3601' Too few parameters. Expected 1" error message.

Message if I do the Forms!.... that you indicated earlier I get "Run-time
error "3601' Too few parameters. Expected 2" error message.

Thank you Allen. Fay


Allen Browne said:
Access asks for parameters if it does not understand one of the names
your table.

Substitute the name of your table for Table1.
Substitute the name of your yes/no field for chkRequested.
If your names have spaces in them, enclose them in square brackets, e.g.
[Table 1]

Good morning Allen thank you for your help. I used the strSql code. It
gets to the last line and gives me the Run-time error "3601' Too few
parameters. Expected 1.

Fay


The article may have been:
Referring to Controls on a Subform
at:
http://allenbrowne.com/casu-04.html

For the example you give, try:
Forms!frmReports!fsubDepartsReqTel.Form!chkRequested


If you have a button on the subform, you could set chkRequeted to no
in the current row with:
Private Sub cmdSetNo_Click()
Me.chkRequested = False
End Sub

If you wanted to change all records to No in Table1:
Dim strSql as String
strSql = "UPDATE Table1 SET chkRequested = False WHERE chkRequested
= True;"
dbEngine(0)(0).Execute strSql, dbFailOnError

1) I had an article a year ago about referencing different controls
and can't find it now. Does any one remember the link to the article
that explains how to reference controls.?

2) My main problem is as follows. On my main form "frmReports" there
is a subform "fsubDepartsReqTel" which has a control "chkRequested".
The subform is a datasheet which lists departments that is used to
select which departments should be reported on. I don't know if I
approached it right but I also put a field in the department table
for requested. I need to make sure that there is a way to set the
value in the table to False. I figured a button would be the
appropriate approach. But I haven't figured out the on click event.
Any help would be appreciated. Thank you.

Using Access03
 

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