Change Checkbox on one form by Checkbox on another form

G

Guest

Hi There,

I have a form Print Assets, with a subform Print Assets Subform. The two
fields that appear in the subform (sourced from Assets) are Asset and
AllowedtoPrint. The AllowedtoPrint is a checkbox and when selected allows
that record to appear in a report. This works fine!

What I want is a checkbox (PrintAllCheck) on the Print Assets form, when
checked to check all AllowedtoPrint checkboxes and if unchecked, uncheck all
AllowedtoPrint checkboxes.

Here's some code I've tried for AfterUdate, but didn't work


Public Sub PrintAllCheck_AfterUpdate()
If PrintAllCheck.Value = True Then
Forms![Assets]![AllowedtoPrint]!Visible = True
Else
Forms![Assets]![AllowedtoPrint]!Visible = False
End If
End Sub


Thanks
 
G

Guest

It is always best, though not always required, to qualify your control names
with either the form name:
Print Assets!PrintAllCheck
or use the Me which means the current form or report:
Me! or Me.

It is not necessary in VBA to use the Value property. It is the default
property returned by the control object.

Brackets are really only required if you are using an Access Reserved Word,
imbedded spaces, or characters that are not normally allowed in a name. The
better habit is to avoid doing so.

When you are addressing a subform, you need the form qualifer with it:
Forms!FromName!SubFormName!ControlName
or
Me!SubFormName!ControlName

Since Visible is a property, is should be prefaces with . rather than !
The . denotes properties and methods. The ! denotes user defined object
names.

So why is Me. allowed?
Don't know for sure, it just is.


Public Sub PrintAllCheck_AfterUpdate()
If Me.PrintAllCheck = True Then
Me.[Print Assets Subform]!AllowedtoPrint.Visible = True
Else
Me.[Print Assets Subform]!AllowedtoPrint.Visible = True
End If
End Sub
 
G

Guest

Chris,

Your code attempts to set the Visible property of a checkbox, which controls
whether it is visible on the form or not. This property does not affect the
control's Value, which is what you want to set. Also, to refer to a subform
control from the main form, you must first refer to the name of the subform
control (by default this is the name of the subform when you dragged it onto
the main form, and then use the Form property to refer to that form *itself*.

While you could change the code to the following,

If PrintAllCheck.Value = True Then
Forms![Print Assets Subform].Form![AllowedtoPrint] = True
Else
Forms![Print Assets Subform].Form![AllowedtoPrint] = False
End If

this will only affect the current record in the subform.

To change all of them to the value of the PrintAllCheck, use an update
query, followed by a subform refresh. Set SetWarnings to False before
running the query to avoid a message box from displaying.

Dim strSQL As String

DoCmd.SetWarnings False
strSQL = "UPDATE Assets " & _
"SET Assets.[AllowedtoPrint] = Forms![Print
Assets]![PrintAllCheck]"
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Me![Print Assets Subform].Form.Refresh

Call the code both in the checkbox' AfterUpdate event procedure and the main
form's OnCurrent or OnOpen event.

Hope that helps.
Sprinks
 
G

Guest

Thanks Sprinks,

It all worked but I still get a run-time error '2450'
.... can't find the form 'Print Assets Subform' refered to in a macro
expression or VB code?

Can you tell me what is going on here?? I was getting this same message
with a some of the other code I was trying!!

Thanks

Sprinks said:
Chris,

Your code attempts to set the Visible property of a checkbox, which controls
whether it is visible on the form or not. This property does not affect the
control's Value, which is what you want to set. Also, to refer to a subform
control from the main form, you must first refer to the name of the subform
control (by default this is the name of the subform when you dragged it onto
the main form, and then use the Form property to refer to that form *itself*.

While you could change the code to the following,

If PrintAllCheck.Value = True Then
Forms![Print Assets Subform].Form![AllowedtoPrint] = True
Else
Forms![Print Assets Subform].Form![AllowedtoPrint] = False
End If

this will only affect the current record in the subform.

To change all of them to the value of the PrintAllCheck, use an update
query, followed by a subform refresh. Set SetWarnings to False before
running the query to avoid a message box from displaying.

Dim strSQL As String

DoCmd.SetWarnings False
strSQL = "UPDATE Assets " & _
"SET Assets.[AllowedtoPrint] = Forms![Print
Assets]![PrintAllCheck]"
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Me![Print Assets Subform].Form.Refresh

Call the code both in the checkbox' AfterUpdate event procedure and the main
form's OnCurrent or OnOpen event.

Hope that helps.
Sprinks


Chris said:
Hi There,

I have a form Print Assets, with a subform Print Assets Subform. The two
fields that appear in the subform (sourced from Assets) are Asset and
AllowedtoPrint. The AllowedtoPrint is a checkbox and when selected allows
that record to appear in a report. This works fine!

What I want is a checkbox (PrintAllCheck) on the Print Assets form, when
checked to check all AllowedtoPrint checkboxes and if unchecked, uncheck all
AllowedtoPrint checkboxes.

Here's some code I've tried for AfterUdate, but didn't work


Public Sub PrintAllCheck_AfterUpdate()
If PrintAllCheck.Value = True Then
Forms![Assets]![AllowedtoPrint]!Visible = True
Else
Forms![Assets]![AllowedtoPrint]!Visible = False
End If
End Sub


Thanks
 
G

Guest

Chris,

It must be that your subform is not named what you think it is. Open the
main form in design view, click on the subform, and choose View, Properties.
Click on the Other tab, and check the value of the Name property. Cut and
paste this value on top of "Print Assets Subform" in the code and it should
work.

If not, cut, paste and post the Name property of the subform, and your
modified AfterUpdate code.

Hope that helps.
Sprinks


Chris said:
Thanks Sprinks,

It all worked but I still get a run-time error '2450'
... can't find the form 'Print Assets Subform' refered to in a macro
expression or VB code?

Can you tell me what is going on here?? I was getting this same message
with a some of the other code I was trying!!

Thanks

Sprinks said:
Chris,

Your code attempts to set the Visible property of a checkbox, which controls
whether it is visible on the form or not. This property does not affect the
control's Value, which is what you want to set. Also, to refer to a subform
control from the main form, you must first refer to the name of the subform
control (by default this is the name of the subform when you dragged it onto
the main form, and then use the Form property to refer to that form *itself*.

While you could change the code to the following,

If PrintAllCheck.Value = True Then
Forms![Print Assets Subform].Form![AllowedtoPrint] = True
Else
Forms![Print Assets Subform].Form![AllowedtoPrint] = False
End If

this will only affect the current record in the subform.

To change all of them to the value of the PrintAllCheck, use an update
query, followed by a subform refresh. Set SetWarnings to False before
running the query to avoid a message box from displaying.

Dim strSQL As String

DoCmd.SetWarnings False
strSQL = "UPDATE Assets " & _
"SET Assets.[AllowedtoPrint] = Forms![Print
Assets]![PrintAllCheck]"
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Me![Print Assets Subform].Form.Refresh

Call the code both in the checkbox' AfterUpdate event procedure and the main
form's OnCurrent or OnOpen event.

Hope that helps.
Sprinks


Chris said:
Hi There,

I have a form Print Assets, with a subform Print Assets Subform. The two
fields that appear in the subform (sourced from Assets) are Asset and
AllowedtoPrint. The AllowedtoPrint is a checkbox and when selected allows
that record to appear in a report. This works fine!

What I want is a checkbox (PrintAllCheck) on the Print Assets form, when
checked to check all AllowedtoPrint checkboxes and if unchecked, uncheck all
AllowedtoPrint checkboxes.

Here's some code I've tried for AfterUdate, but didn't work


Public Sub PrintAllCheck_AfterUpdate()
If PrintAllCheck.Value = True Then
Forms![Assets]![AllowedtoPrint]!Visible = True
Else
Forms![Assets]![AllowedtoPrint]!Visible = False
End If
End Sub


Thanks
 
G

Guest

Thanks heaps for your help - it worked, but now I get a different error!!

The data has been changed
Another User edited this record and saved the changes before you attempted
to change your changes.

Also, how do I find out the name of a main form??

Thanks


Sprinks said:
Chris,

It must be that your subform is not named what you think it is. Open the
main form in design view, click on the subform, and choose View, Properties.
Click on the Other tab, and check the value of the Name property. Cut and
paste this value on top of "Print Assets Subform" in the code and it should
work.

If not, cut, paste and post the Name property of the subform, and your
modified AfterUpdate code.

Hope that helps.
Sprinks


Chris said:
Thanks Sprinks,

It all worked but I still get a run-time error '2450'
... can't find the form 'Print Assets Subform' refered to in a macro
expression or VB code?

Can you tell me what is going on here?? I was getting this same message
with a some of the other code I was trying!!

Thanks

Sprinks said:
Chris,

Your code attempts to set the Visible property of a checkbox, which controls
whether it is visible on the form or not. This property does not affect the
control's Value, which is what you want to set. Also, to refer to a subform
control from the main form, you must first refer to the name of the subform
control (by default this is the name of the subform when you dragged it onto
the main form, and then use the Form property to refer to that form *itself*.

While you could change the code to the following,

If PrintAllCheck.Value = True Then
Forms![Print Assets Subform].Form![AllowedtoPrint] = True
Else
Forms![Print Assets Subform].Form![AllowedtoPrint] = False
End If

this will only affect the current record in the subform.

To change all of them to the value of the PrintAllCheck, use an update
query, followed by a subform refresh. Set SetWarnings to False before
running the query to avoid a message box from displaying.

Dim strSQL As String

DoCmd.SetWarnings False
strSQL = "UPDATE Assets " & _
"SET Assets.[AllowedtoPrint] = Forms![Print
Assets]![PrintAllCheck]"
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Me![Print Assets Subform].Form.Refresh

Call the code both in the checkbox' AfterUpdate event procedure and the main
form's OnCurrent or OnOpen event.

Hope that helps.
Sprinks


:

Hi There,

I have a form Print Assets, with a subform Print Assets Subform. The two
fields that appear in the subform (sourced from Assets) are Asset and
AllowedtoPrint. The AllowedtoPrint is a checkbox and when selected allows
that record to appear in a report. This works fine!

What I want is a checkbox (PrintAllCheck) on the Print Assets form, when
checked to check all AllowedtoPrint checkboxes and if unchecked, uncheck all
AllowedtoPrint checkboxes.

Here's some code I've tried for AfterUdate, but didn't work


Public Sub PrintAllCheck_AfterUpdate()
If PrintAllCheck.Value = True Then
Forms![Assets]![AllowedtoPrint]!Visible = True
Else
Forms![Assets]![AllowedtoPrint]!Visible = False
End If
End Sub


Thanks
 
G

Guest

Chris,

The name of a main form is what it is listed at on the Forms tab in database
view. Also, by Default, Access sets the form's Caption property to the name
of the form, although you can change it.

As to your multi-user error, I'm afraid I can't help; I'm just now
developing multi-user applications.

Sprinks


Chris said:
Thanks heaps for your help - it worked, but now I get a different error!!

The data has been changed
Another User edited this record and saved the changes before you attempted
to change your changes.

Also, how do I find out the name of a main form??

Thanks


Sprinks said:
Chris,

It must be that your subform is not named what you think it is. Open the
main form in design view, click on the subform, and choose View, Properties.
Click on the Other tab, and check the value of the Name property. Cut and
paste this value on top of "Print Assets Subform" in the code and it should
work.

If not, cut, paste and post the Name property of the subform, and your
modified AfterUpdate code.

Hope that helps.
Sprinks


Chris said:
Thanks Sprinks,

It all worked but I still get a run-time error '2450'
... can't find the form 'Print Assets Subform' refered to in a macro
expression or VB code?

Can you tell me what is going on here?? I was getting this same message
with a some of the other code I was trying!!

Thanks

:

Chris,

Your code attempts to set the Visible property of a checkbox, which controls
whether it is visible on the form or not. This property does not affect the
control's Value, which is what you want to set. Also, to refer to a subform
control from the main form, you must first refer to the name of the subform
control (by default this is the name of the subform when you dragged it onto
the main form, and then use the Form property to refer to that form *itself*.

While you could change the code to the following,

If PrintAllCheck.Value = True Then
Forms![Print Assets Subform].Form![AllowedtoPrint] = True
Else
Forms![Print Assets Subform].Form![AllowedtoPrint] = False
End If

this will only affect the current record in the subform.

To change all of them to the value of the PrintAllCheck, use an update
query, followed by a subform refresh. Set SetWarnings to False before
running the query to avoid a message box from displaying.

Dim strSQL As String

DoCmd.SetWarnings False
strSQL = "UPDATE Assets " & _
"SET Assets.[AllowedtoPrint] = Forms![Print
Assets]![PrintAllCheck]"
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
Me![Print Assets Subform].Form.Refresh

Call the code both in the checkbox' AfterUpdate event procedure and the main
form's OnCurrent or OnOpen event.

Hope that helps.
Sprinks


:

Hi There,

I have a form Print Assets, with a subform Print Assets Subform. The two
fields that appear in the subform (sourced from Assets) are Asset and
AllowedtoPrint. The AllowedtoPrint is a checkbox and when selected allows
that record to appear in a report. This works fine!

What I want is a checkbox (PrintAllCheck) on the Print Assets form, when
checked to check all AllowedtoPrint checkboxes and if unchecked, uncheck all
AllowedtoPrint checkboxes.

Here's some code I've tried for AfterUdate, but didn't work


Public Sub PrintAllCheck_AfterUpdate()
If PrintAllCheck.Value = True Then
Forms![Assets]![AllowedtoPrint]!Visible = True
Else
Forms![Assets]![AllowedtoPrint]!Visible = False
End If
End Sub


Thanks
 

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