Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting values on subform

Status
Not open for further replies.

2Grandpa

Programmer
Jun 13, 2003
38
US
The code below worked fine on a TAB form for a record with 16 characteristics. They changed the number of charactersitices to 50 so I wanted to use a subform so the other TAB formating would not be affected.

The problem is with the statement "Me(MCharF).Value = MCCF"
which sets the value of controls CC1 - CC50 as it goes through the procedure. I get an "Cannot find field" error message.

MCharF = "Forms![frmProductAuditA]![SOFChar].Form![CC1]" when the error message appears.






Private Sub SubcboCC() ' New procedure 1/13/05

Dim MCC, MCharF As String, Mcount As Integer, MCCF, MChar, MDobsF As String, MPobs As Variant, MPobsF As Variant, MDobs As Variant, MDobFs As Variant

MCC = "CC"
MPobs = "ProdObs"
MDobs = "DefcObs"
MChar = "CC"
Mcount = 1
MCCF = MCC & Mcount
MPobsF = "Forms![frmProductAuditA]![SOFChar].Form!" & "[" & MPobs & Mcount & "]"
MDobsF = "Forms![frmProductAuditA]![SOFChar].Form!" & "[" & MDobs & Mcount & "]"
MCharF = "Forms![frmProductAuditA]![SOFChar].Form!" & "[" & MChar & Mcount & "]"
Do While Mcount < 51
MCCF = DLookup(MCCF, "Partno", "[PartNo] = Forms!frmProductAuditA!cboPartNumber")
Me(MCharF).Value = MCCF
If MCCF Then
Me(MPobsF).BackColor = 52479
Me(MDobsF).BackColor = 52479
Else
Me(MPobsF).BackColor = 16777215
Me(MDobsF).BackColor = 16777215
End If
Mcount = Mcount + 1 'Increase Mcount by 1 for next loop
MCCF = MCC & Mcount 'Likewise, change field to CC2 etc
MPobsF = MPobs & Mcount
MDobsF = MDobs & Mcount
MCharF = MChar & Mcount

Loop 'Start routine all over

End Sub

 
try using the controls collection of the subform control form object:

MPobsF = "Forms![frmProductAuditA]![SOFChar].Form.Controls(" & chr$(34) & MPobs & Mcount & chr$(34) & ")"

Also, you know that your dimension strategy:

Dim MCC, MCharF As String, Mcount As Integer, MCCF, MChar, MDobsF As String, MPobs As Variant, MPobsF As Variant, MDobs As Variant, MDobFs As Variant

...dimensions MCC, MCCF, and MChar as Variants, right?

You are not explicitly declaring their type, and you can't dimension a list of items as a type:

Dim String1, String2, String3 as String

Only String3 will actually be a string. The other two will be Variants.

HTH
 
rubbernilly,
Thanks for reply. But it did not work. Since we were using forms controls I tried using the inserted form name but that did not work. I also tried single quoter. chr$(39) and various other but not luck. The variable looked like this
MPobsF = "Forms![frmProductAuditA]![SOFChar].Form.Controls("ProdObs1")"

 
Something like this ?
MCC = "CC"
MPobs = "ProdObs"
MDobs = "DefcObs"
MChar = "CC"
Mcount = 1
Do While Mcount < 51
MCCF = MCC & Mcount
MPobsF = MPobs & Mcount
MDobsF = MDobs & Mcount
MCharF = MChar & Mcount
MCCF = DLookup(MCCF, "Partno", "[PartNo] = Forms!frmProductAuditA!cboPartNumber")
Forms!frmProductAuditA!SOFChar.Form.Controls(MCharF).Value = MCCF
If MCCF Then
Forms!frmProductAuditA!SOFChar.Form.Controls(MPobsF).BackColor = 52479
Forms!frmProductAuditA!SOFChar.Form.Controls(MDobsF).BackColor = 52479
Else
Forms!frmProductAuditA!SOFChar.Form.Controls(MPobsF).BackColor = 16777215
Forms!frmProductAuditA!SOFChar.Form.Controls(MDobsF).BackColor = 16777215
End If
Mcount = Mcount + 1
Loop

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top