VB Code on Click

  • Thread starter Jessica Reinhardt
  • Start date
J

Jessica Reinhardt

I am attempting to use the solution you suggest, but am running into an error when the subform is added to the main form.

The check boxes are greyed out, and when I try to click one the message:

Run-time error '3201' You cannot add or change a record because a related record is required in table Houses (my equivalent to Product).

Any idea where the problem might be coming in? I removed the linking fields as you recommended, and have double checked that the VB on click is correct, but on debug it highlights the Me.Requery.

Thanks in advance



Steve wrote:

Re: store multiple selection of list box in table field
28-Jun-09

Hello Irene

You need the following tables
TblProduc
ProductI
ProductNam
et

TblCategor
CategoryI
Categor

TblProductCategor
ProductCategoryI
ProductI
CategoryI
CategorySelected (Yes/No

Create the standard relationships and enforce referential integrity

1. Create a query named QryProductCategory based on TblProductCategory.
Pull down all the fields. Set the criteria of ProductID to:
Forms!FrmProduct!ProductID. (You will create this form later!
2. Create a query named QrySFrmProductCategory. Include TblCategory and
QryProductCategory. Pull down Category from TblCategory and all the fields
from QryProductCategory. Join CategoryID in TblCategory to CategoryID in
QryProductCategory. Click on the join line and select the type of join that
says Include all records in TblCategory and only those in QryProductCategory
where the joined fields are equal
3. Create a form/subform
A. Base the main form on TblProduct and name the main form
FrmProduct. Be sure to include all fields from TblProduct
B. Base the subform on QrySFrmProductCategory. Name the subform
SFrmProductCategory. Male the subform a continuous form. Put the fields in
this order
CategorySelected, Category, CategoryID, ProductI
Make CategoryID and ProductID not visible
C. Put the following code in the Click event of CategorySelected
If Not IsNull(Me!ProductID) The
DoCmd.SetWarnings Fals
DoCmd.RunCommand acCmdDeleteRecor
DoCmd.SetWarnings Fals
Me.Requer
En
End I
Me!ProductID = Forms!FrmProduct!ProductI
D. Open the main form in design view and select the subform control.
Open properties and go to the Data tab. Make sure the LinkMaster and
Linkchild properties are blank
4. Close everything and you are ready to go

When you open FrmProduct you should see a product in the main form and in
the subform a list of all the categories in TblCategory with a checkbox
beside each category. All you have to do is check each category that applies
to the product in the main form

Stev
(e-mail address removed)






EggHeadCafe - Software Developer Portal of Choice
Custom Self-Expanding Multiselect Winforms ListBox
http://www.eggheadcafe.com/tutorial...58-8c7b8a74319a/custom-selfexpanding-mul.aspx
 

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