Update multiple fields if checkbox=true

G

Guest

WindowsXP Pro, Access 2003, familiar with VBA.

I have a continuous form with fields based on a query "PRACHECKLIST" which
is based on a table "EVMASTER". Some of the fields are for owner information
- "LASTNAME", "FIRSTNAME", etc. There is also a checkbox named
"PRACHECKBOX". All of this is in the detail section of the form. The
purpose of this form is to allow the user to select specific records using
the checkbox. They then enter the owner information into unbound text boxes
in the form footer. This information is then passed to a report "PRA" which
prints all records and the owner information which we have the owner sign
when they pick up the selected items.

What I am trying to do is to pass the owner information from the unbound
text boxes to the corresponding owner information fields for records where
the checkbox = true when the form is printed. The form is printed using a
command button with an onclick event.
 
J

JethroUK©

easiest way is to use the form filter

Filter = 'mycheckbox = yes'
Filteron = true

print my records

filteron = false


| WindowsXP Pro, Access 2003, familiar with VBA.
|
| I have a continuous form with fields based on a query "PRACHECKLIST" which
| is based on a table "EVMASTER". Some of the fields are for owner
information
| - "LASTNAME", "FIRSTNAME", etc. There is also a checkbox named
| "PRACHECKBOX". All of this is in the detail section of the form. The
| purpose of this form is to allow the user to select specific records using
| the checkbox. They then enter the owner information into unbound text
boxes
| in the form footer. This information is then passed to a report "PRA"
which
| prints all records and the owner information which we have the owner sign
| when they pick up the selected items.
|
| What I am trying to do is to pass the owner information from the unbound
| text boxes to the corresponding owner information fields for records where
| the checkbox = true when the form is printed. The form is printed using a
| command button with an onclick event.
| --
| I'm not young enough to know everything.
 
G

Guest

I don't believe you understand what I am looking for. I don't have a problem
printing the records. I want to take the information entered into the
unbound control "LASTNAME" and place it into the field "OWN_LAST" for every
record where "PRACHECKBOX" equals "TRUE". I was trying to place this action
into the OnClick event of the Command Button that prints a report.
 
J

JethroUK©

i would say the best method is to get them to add their name first, then
update the field using checkbox after update

sub checkbox_afterupdate
myfield = mytextbox
end sub

if it's crucial they add their name afterwards then the best method is to
run an Update query where mycheckbox = True




| I don't believe you understand what I am looking for. I don't have a
problem
| printing the records. I want to take the information entered into the
| unbound control "LASTNAME" and place it into the field "OWN_LAST" for
every
| record where "PRACHECKBOX" equals "TRUE". I was trying to place this
action
| into the OnClick event of the Command Button that prints a report.
| --
| I'm not young enough to know everything.
|
|
| "JethroUK©" wrote:
|
| > easiest way is to use the form filter
| >
| > Filter = 'mycheckbox = yes'
| > Filteron = true
| >
| > print my records
| >
| > filteron = false
| >
| >
| > | > | WindowsXP Pro, Access 2003, familiar with VBA.
| > |
| > | I have a continuous form with fields based on a query "PRACHECKLIST"
which
| > | is based on a table "EVMASTER". Some of the fields are for owner
| > information
| > | - "LASTNAME", "FIRSTNAME", etc. There is also a checkbox named
| > | "PRACHECKBOX". All of this is in the detail section of the form. The
| > | purpose of this form is to allow the user to select specific records
using
| > | the checkbox. They then enter the owner information into unbound text
| > boxes
| > | in the form footer. This information is then passed to a report "PRA"
| > which
| > | prints all records and the owner information which we have the owner
sign
| > | when they pick up the selected items.
| > |
| > | What I am trying to do is to pass the owner information from the
unbound
| > | text boxes to the corresponding owner information fields for records
where
| > | the checkbox = true when the form is printed. The form is printed
using a
| > | command button with an onclick event.
| > | --
| > | I'm not young enough to know everything.
| >
| >
| >
 
J

JethroUK©

CurrentDb.Execute "UPDATE mytable SET myfield = " & mytextbox & "WHERE
mycheckfield = Yes"


| i would say the best method is to get them to add their name first, then
| update the field using checkbox after update
|
| sub checkbox_afterupdate
| myfield = mytextbox
| end sub
|
| if it's crucial they add their name afterwards then the best method is to
| run an Update query where mycheckbox = True
|
|
|
|
| | | I don't believe you understand what I am looking for. I don't have a
| problem
| | printing the records. I want to take the information entered into the
| | unbound control "LASTNAME" and place it into the field "OWN_LAST" for
| every
| | record where "PRACHECKBOX" equals "TRUE". I was trying to place this
| action
| | into the OnClick event of the Command Button that prints a report.
| | --
| | I'm not young enough to know everything.
| |
| |
| | "JethroUK©" wrote:
| |
| | > easiest way is to use the form filter
| | >
| | > Filter = 'mycheckbox = yes'
| | > Filteron = true
| | >
| | > print my records
| | >
| | > filteron = false
| | >
| | >
| | > | | > | WindowsXP Pro, Access 2003, familiar with VBA.
| | > |
| | > | I have a continuous form with fields based on a query "PRACHECKLIST"
| which
| | > | is based on a table "EVMASTER". Some of the fields are for owner
| | > information
| | > | - "LASTNAME", "FIRSTNAME", etc. There is also a checkbox named
| | > | "PRACHECKBOX". All of this is in the detail section of the form.
The
| | > | purpose of this form is to allow the user to select specific records
| using
| | > | the checkbox. They then enter the owner information into unbound
text
| | > boxes
| | > | in the form footer. This information is then passed to a report
"PRA"
| | > which
| | > | prints all records and the owner information which we have the owner
| sign
| | > | when they pick up the selected items.
| | > |
| | > | What I am trying to do is to pass the owner information from the
| unbound
| | > | text boxes to the corresponding owner information fields for records
| where
| | > | the checkbox = true when the form is printed. The form is printed
| using a
| | > | command button with an onclick event.
| | > | --
| | > | I'm not young enough to know everything.
| | >
| | >
| | >
|
|
 
G

Guest

I'm still having a problem.

I tried the following:
------------Code Start-------------------
Private Sub testbutton_Click()

'CurrentDb.Execute "UPDATE mytable SET myfield = " & mytextbox & " WHERE
mycheckfield = Yes"

CurrentDb.Execute "UPDATE EVMASTER SET OWNLAST = " & LASTname & " WHERE
PRACHECKBOX = True"

End Sub
-------------Code End-------------------

I changed the "YES" to "TRUE" since my version of Access uses True/False
checkbox values. I tried several different variations of this code to no
avail - I keep getting a message "Run-time error '3061': Too few parameters.
Expected 1." I checked all of the field names, control names, and table
names to make sure they were correct. I use similar code to reset the
checkboxes when the form is closed and it works fine.

Here is that code:
------------Code Start-------------------
Dim strSQL As String

strSQL = "UPDATE EVMASTER SET PRACHECKBOX = False WHERE PRACHECKBOX = True;"
DBEngine(0)(0).Execute strSQL, dbFailOnError

DoCmd.Close
-------------Code End-------------------

I am certain there is a syntax problem, but I can't find it.
 
G

Guest

I'm getting closer! I narrowed down the cause of the error. Using the
following code:
-----------Code Start------------
Private Sub testbutton_Click()
Me.Refresh
strSQL = "UPDATE EVMASTER SET EVMASTER.OWNLAST =
'FORMS!PRACHECKLIST!LASTNAME'" & " WHERE EVMASTER.PRACHECKBOX = True;"
DBEngine(0)(0).Execute strSQL, dbFailOnError
Me.Refresh
End Sub
-----------Code End-------------

I added single quotes around the LASTNAME control to see if the basic
function would work and it did - of course it enters the text
"FORMS!PRACHECKLIST!LASTNAME" in the appropriate fields instead of the value.
When I remove the single quotes to try to put the value in the fields, I get
the error. Therefore, the error must be in the syntax of the LASTNAME
control value. This value comes from an unbound control [LASTNAME] on the
form [PRACHECKLIST] where all of this is being done. What would the syntax
be for this?
 
J

JethroUK©

try:

strSQL = "UPDATE EVMASTER SET EVMASTER.OWNLAST = " & me.LASTNAME & " WHERE
EVMASTER.PRACHECKBOX = True;"

this assumes 'Lastname" is name of the textbox in your form footer (could
cause issues if you have a field with same name)

note the inclusion of space before the Where clause - " Where......"

note also that me.lastname must be updated (press ENTER) for it to truly
contain the value

if that fails - i always check syntax by actually setting up the query
(substitue me.lastname with any word) - check it works (updates correctly) -
switch to SQL view and copy/paste the sql code directly - replace the 'word'
with : & me.LASTNAME &


| I'm getting closer! I narrowed down the cause of the error. Using the
| following code:
| -----------Code Start------------
| Private Sub testbutton_Click()
| Me.Refresh
| strSQL = "UPDATE EVMASTER SET EVMASTER.OWNLAST =
| 'FORMS!PRACHECKLIST!LASTNAME'" & " WHERE EVMASTER.PRACHECKBOX = True;"
| DBEngine(0)(0).Execute strSQL, dbFailOnError
| Me.Refresh
| End Sub
| -----------Code End-------------
|
| I added single quotes around the LASTNAME control to see if the basic
| function would work and it did - of course it enters the text
| "FORMS!PRACHECKLIST!LASTNAME" in the appropriate fields instead of the
value.
| When I remove the single quotes to try to put the value in the fields, I
get
| the error. Therefore, the error must be in the syntax of the LASTNAME
| control value. This value comes from an unbound control [LASTNAME] on the
| form [PRACHECKLIST] where all of this is being done. What would the
syntax
| be for this?
| --
| I'm not young enough to know everything.
|
|
| "JethroUK©" wrote:
|
| > CurrentDb.Execute "UPDATE mytable SET myfield = " & mytextbox & "WHERE
| > mycheckfield = Yes"
| >
| >
| > | > | i would say the best method is to get them to add their name first,
then
| > | update the field using checkbox after update
| > |
| > | sub checkbox_afterupdate
| > | myfield = mytextbox
| > | end sub
| > |
| > | if it's crucial they add their name afterwards then the best method is
to
| > | run an Update query where mycheckbox = True
| > |
| > |
| > |
| > |
| > | | > | | I don't believe you understand what I am looking for. I don't have
a
| > | problem
| > | | printing the records. I want to take the information entered into
the
| > | | unbound control "LASTNAME" and place it into the field "OWN_LAST"
for
| > | every
| > | | record where "PRACHECKBOX" equals "TRUE". I was trying to place
this
| > | action
| > | | into the OnClick event of the Command Button that prints a report.
| > | | --
| > | | I'm not young enough to know everything.
| > | |
| > | |
| > | | "JethroUK©" wrote:
| > | |
| > | | > easiest way is to use the form filter
| > | | >
| > | | > Filter = 'mycheckbox = yes'
| > | | > Filteron = true
| > | | >
| > | | > print my records
| > | | >
| > | | > filteron = false
| > | | >
| > | | >
| > | | > | > | | > | WindowsXP Pro, Access 2003, familiar with VBA.
| > | | > |
| > | | > | I have a continuous form with fields based on a query
"PRACHECKLIST"
| > | which
| > | | > | is based on a table "EVMASTER". Some of the fields are for
owner
| > | | > information
| > | | > | - "LASTNAME", "FIRSTNAME", etc. There is also a checkbox named
| > | | > | "PRACHECKBOX". All of this is in the detail section of the
form.
| > The
| > | | > | purpose of this form is to allow the user to select specific
records
| > | using
| > | | > | the checkbox. They then enter the owner information into
unbound
| > text
| > | | > boxes
| > | | > | in the form footer. This information is then passed to a report
| > "PRA"
| > | | > which
| > | | > | prints all records and the owner information which we have the
owner
| > | sign
| > | | > | when they pick up the selected items.
| > | | > |
| > | | > | What I am trying to do is to pass the owner information from the
| > | unbound
| > | | > | text boxes to the corresponding owner information fields for
records
| > | where
| > | | > | the checkbox = true when the form is printed. The form is
printed
| > | using a
| > | | > | command button with an onclick event.
| > | | > | --
| > | | > | I'm not young enough to know everything.
| > | | >
| > | | >
| > | | >
| > |
| > |
| >
| >
| >
 
G

Guest

Thank you for all of your help. I tried everything you suggested and for
some reason, it would not accept the code when I tried to use the value. I
did find a solution, however. I created a simple update query and set it to
run with the print report function.

Sometimes it's hard to see the forest for the trees. Thanks again.
--
I'm not young enough to know everything.


JethroUK© said:
try:

strSQL = "UPDATE EVMASTER SET EVMASTER.OWNLAST = " & me.LASTNAME & " WHERE
EVMASTER.PRACHECKBOX = True;"

this assumes 'Lastname" is name of the textbox in your form footer (could
cause issues if you have a field with same name)

note the inclusion of space before the Where clause - " Where......"

note also that me.lastname must be updated (press ENTER) for it to truly
contain the value

if that fails - i always check syntax by actually setting up the query
(substitue me.lastname with any word) - check it works (updates correctly) -
switch to SQL view and copy/paste the sql code directly - replace the 'word'
with : & me.LASTNAME &


| I'm getting closer! I narrowed down the cause of the error. Using the
| following code:
| -----------Code Start------------
| Private Sub testbutton_Click()
| Me.Refresh
| strSQL = "UPDATE EVMASTER SET EVMASTER.OWNLAST =
| 'FORMS!PRACHECKLIST!LASTNAME'" & " WHERE EVMASTER.PRACHECKBOX = True;"
| DBEngine(0)(0).Execute strSQL, dbFailOnError
| Me.Refresh
| End Sub
| -----------Code End-------------
|
| I added single quotes around the LASTNAME control to see if the basic
| function would work and it did - of course it enters the text
| "FORMS!PRACHECKLIST!LASTNAME" in the appropriate fields instead of the
value.
| When I remove the single quotes to try to put the value in the fields, I
get
| the error. Therefore, the error must be in the syntax of the LASTNAME
| control value. This value comes from an unbound control [LASTNAME] on the
| form [PRACHECKLIST] where all of this is being done. What would the
syntax
| be for this?
| --
| I'm not young enough to know everything.
|
|
| "JethroUK©" wrote:
|
| > CurrentDb.Execute "UPDATE mytable SET myfield = " & mytextbox & "WHERE
| > mycheckfield = Yes"
| >
| >
| > | > | i would say the best method is to get them to add their name first,
then
| > | update the field using checkbox after update
| > |
| > | sub checkbox_afterupdate
| > | myfield = mytextbox
| > | end sub
| > |
| > | if it's crucial they add their name afterwards then the best method is
to
| > | run an Update query where mycheckbox = True
| > |
| > |
| > |
| > |
| > | | > | | I don't believe you understand what I am looking for. I don't have
a
| > | problem
| > | | printing the records. I want to take the information entered into
the
| > | | unbound control "LASTNAME" and place it into the field "OWN_LAST"
for
| > | every
| > | | record where "PRACHECKBOX" equals "TRUE". I was trying to place
this
| > | action
| > | | into the OnClick event of the Command Button that prints a report.
| > | | --
| > | | I'm not young enough to know everything.
| > | |
| > | |
| > | | "JethroUK©" wrote:
| > | |
| > | | > easiest way is to use the form filter
| > | | >
| > | | > Filter = 'mycheckbox = yes'
| > | | > Filteron = true
| > | | >
| > | | > print my records
| > | | >
| > | | > filteron = false
| > | | >
| > | | >
| > | | > | > | | > | WindowsXP Pro, Access 2003, familiar with VBA.
| > | | > |
| > | | > | I have a continuous form with fields based on a query
"PRACHECKLIST"
| > | which
| > | | > | is based on a table "EVMASTER". Some of the fields are for
owner
| > | | > information
| > | | > | - "LASTNAME", "FIRSTNAME", etc. There is also a checkbox named
| > | | > | "PRACHECKBOX". All of this is in the detail section of the
form.
| > The
| > | | > | purpose of this form is to allow the user to select specific
records
| > | using
| > | | > | the checkbox. They then enter the owner information into
unbound
| > text
| > | | > boxes
| > | | > | in the form footer. This information is then passed to a report
| > "PRA"
| > | | > which
| > | | > | prints all records and the owner information which we have the
owner
| > | sign
| > | | > | when they pick up the selected items.
| > | | > |
| > | | > | What I am trying to do is to pass the owner information from the
| > | unbound
| > | | > | text boxes to the corresponding owner information fields for
records
| > | where
| > | | > | the checkbox = true when the form is printed. The form is
printed
| > | using a
| > | | > | command button with an onclick event.
| > | | > | --
| > | | > | I'm not young enough to know everything.
| > | | >
| > | | >
| > | | >
| > |
| > |
| >
| >
| >
 

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