PDA

View Full Version : Help assigning values to fields in a subform



mtevans
09-12-2008, 12:14 PM
Hi,

I have a main form (mainfrm1) with a button that calls another main form (Mainfrm2)that contains a subform. The values on the mainfrm1 are assigned to the controls in the subform of the mainfrm2.

The code runs on the click event of the button in mainfrm1. I am getting an error that the subform is not being recognized when the mainfrm2 is being called. This code worked before I made the subform a subform and was calling it directly. Since I added in the mainfrm2 level it now throws the error.

Any help would be greatly appreciated.

thanks,
Maureen

Private Sub OldMerchant_Click()
On Error GoTo Err_OldMerchant_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim tmpDba As Variant
Dim tmpMID As Variant
Dim tmpFirstName As Variant
Dim tmpLastName As Variant
Dim tmpPhone As Variant
Dim tmpEmail As Variant
Dim tmpPrin As Variant
Dim tmpAssoc As Variant
Dim tmpChain As Variant

stDocName = "mainfrm2"
DoCmd.OpenForm stDocName, , , stLinkCriteria

' assign variables
tmpDba = Forms!MerchantLU!MerchantName
tmpMID = Forms!MerchantLU!MerchantIDLU
tmpPhone = Forms!MerchantLU!Phone
tmpEmail = Forms!MerchantLU!Email
tmpPrin = Forms!MerchantLU!Principal
tmpAssoc = Forms!MerchantLU!Associate
tmpChain = Forms!MerchantLU!Chain

Forms!mainfrm2!GAAOrderFormDE.Form.DBAName = tmpDba
Forms!mainfrm2!GAAOrderFormDE.Form.MerchantNumber = tmpMID
Forms!mainfrm2!GAAOrderFormDE.Form.ContactPhone = tmpPhone
Forms!mainfrm2!GAAOrderFormDE.Form.Email = tmpEmail
Forms!mainfrm2!GAAOrderFormDE.Form.Prin = tmpPrin
Forms!mainfrm2!GAAOrderFormDE.Form.Assoc = tmpAssoc
Forms!mainfrm2!GAAOrderFormDE.Form.Chain = tmpChain

Exit_OldMerchant_Click:
Exit Sub
Err_OldMerchant_Click:
MsgBox Err.Description
Resume Exit_OldMerchant_Click

End Sub

ibgreat
09-13-2008, 09:37 AM
Forms!mainfrm2!GAAOrderFormDE.Form.DBAName = tmpDba

I am certainly no expert with subforms and frequently run into some problems myself. But, is GAAOrderFormDE the name of your subform or the control on the mainform. This is a frequent mistake, that took me awhile to figure out. Also, I think in your case you you are correct and should include the last Form reference, however, you may want to try it without.

Forms!mainfrm2!GAAOrderFormDE.DBAName = tmpDba

Outside of the very pragmatic answers, I am not clear about why you are launching another form with identical information. (I'm certain you have a good reason.) Also how is the subform related to MainForm2?