Using Checkboxes in Subforms

G

Guest

I have a main form that has as its recordsource a table (tblControl) with 4
fields (control number (DMax generated), name, date, type). Its subform is
linked by type and in continuous view displays any records in my data table
(tblReceipts)without a control number.

I originally had it set up for the user to enter the control number
displayed on the main form into the empty field displayed in the subform, but
quickly deduced that this was a poor choice in design - the user could enter
any number that was a valid record in tblControl (since there is referential
integrity between the tables).

I'd like to place a checkbox on the subform for the user to identify the
records that should be updated with the main form's control number. I'm
thinking I should use a BeforeUpdate procedure, but I'm struggling with the
correct code.

Thanks so much for your assistance.
 
B

Barry-Jon

You could create a command button on the subform with an on click event
with something like the following;

Me.txtControlNbr.Value = Me.Parent.Controls("txtControlNbr").Value

I am assuming here that you have a control (hidden or otherwise) called
txtControlNbr on your subform. I am also assuming that you have a
similar control on the parent form.

You might want to also include a Me.Form.Requery after that line. That
would cause the selected record to immediately disappear.

Not quite checkboxes but does the same thing in one click per record.
 
G

Guest

Thanks for the help. I continue to get an error message however - I don't
think I have the punctuation or something. Following your directions, and
some data I found on how to refer to parent & subforms I think it should read
something like:

Me.DepositControlNumber.Value = Me.Parent!(ControlNumber).Value

When I press the button tho, I get an evaluation error. I'm sure it's more
simple than I'm making it. . . . .
 
J

John Vinson

I have a main form that has as its recordsource a table (tblControl) with 4
fields (control number (DMax generated), name, date, type). Its subform is
linked by type and in continuous view displays any records in my data table
(tblReceipts)without a control number.

I originally had it set up for the user to enter the control number
displayed on the main form into the empty field displayed in the subform, but
quickly deduced that this was a poor choice in design - the user could enter
any number that was a valid record in tblControl (since there is referential
integrity between the tables).

I'd like to place a checkbox on the subform for the user to identify the
records that should be updated with the main form's control number. I'm
thinking I should use a BeforeUpdate procedure, but I'm struggling with the
correct code.

I'd suggest a different approach: if you want the user to be able to
select any record on the subform and thereby assign it the main form's
Control Number, put a Command Button on the subform (cmdControlNumber
I'll call it). Select its Click event and click the ... icon by it;
invoke the Code Builder and edit the code to something like

Private Sub cmdControlNumber_Click()
Me!ControlNumber = Parent!ControlNumber
End Sub

using of course your own control names for the ControlNumber textboxes
or other controls. Set the subform's ControlNumber textbox to Enabled
= False, Locked = True to keep the user from typing anything into it.

John W. Vinson[MVP]
 
J

John Vinson

Thanks for the help. I continue to get an error message however - I don't
think I have the punctuation or something. Following your directions, and
some data I found on how to refer to parent & subforms I think it should read
something like:

Me.DepositControlNumber.Value = Me.Parent!(ControlNumber).Value

When I press the button tho, I get an evaluation error. I'm sure it's more
simple than I'm making it. . . . .

Yep. Remove the parentheses.

John W. Vinson[MVP]
 

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