G
Guest
My Access 2003 project consists of a switchboard with several sub forms all
positioned on top of one another. On the switchboard is a number of command
buttons which makes each sub form visible or not. All works great.
On one of my subforms i have a print envelope command button which looks at
values on the same subform and copies them to a table. The code is as follows:
Sub AddAddressToEnvelope()
On Error GoTo Err_AddAddressToEnvelope
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.Title = Forms!sbfrmSwitchboardCustomers.combo101"
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.FirstName =
Forms!sbfrmSwitchboardCustomers.FirstName"
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.LastName = Forms!sbfrmSwitchboardCustomers.LastName"
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.Company = Forms!sbfrmSwitchboardCustomers.Company"
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.Address1 = Forms!sbfrmSwitchboardCustomers.Address1"
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.Address2 = Forms!sbfrmSwitchboardCustomers.Address2"
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.City = Forms!sbfrmSwitchboardCustomers.City"
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.County = Forms!sbfrmSwitchboardCustomers.County"
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.PostCode = Forms!sbfrmSwitchboardCustomers.PostCode"
DoCmd.SetWarnings True
Exit_AddAddressToEnvelope:
Exit Sub
Err_AddAddressToEnvelope:
MsgBox Err.Number & Err.Description, , CurrentDb.Properties("AppTitle")
Resume Exit_AddAddressToEnvelope
End Sub
This vba code works exactly as it should when the sub form is opened on its
own, without the switchboard but when the project is opened up without using
the shift key and the switchboard opens, the vba code cant find all the
variables eg Forms!sbfrmSwitchboardCustomers.PostCode"
Any ideas anyone, please.
positioned on top of one another. On the switchboard is a number of command
buttons which makes each sub form visible or not. All works great.
On one of my subforms i have a print envelope command button which looks at
values on the same subform and copies them to a table. The code is as follows:
Sub AddAddressToEnvelope()
On Error GoTo Err_AddAddressToEnvelope
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.Title = Forms!sbfrmSwitchboardCustomers.combo101"
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.FirstName =
Forms!sbfrmSwitchboardCustomers.FirstName"
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.LastName = Forms!sbfrmSwitchboardCustomers.LastName"
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.Company = Forms!sbfrmSwitchboardCustomers.Company"
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.Address1 = Forms!sbfrmSwitchboardCustomers.Address1"
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.Address2 = Forms!sbfrmSwitchboardCustomers.Address2"
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.City = Forms!sbfrmSwitchboardCustomers.City"
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.County = Forms!sbfrmSwitchboardCustomers.County"
DoCmd.RunSQL "UPDATE tblPrintingOnToEnvelopes SET
tblPrintingOnToEnvelopes.PostCode = Forms!sbfrmSwitchboardCustomers.PostCode"
DoCmd.SetWarnings True
Exit_AddAddressToEnvelope:
Exit Sub
Err_AddAddressToEnvelope:
MsgBox Err.Number & Err.Description, , CurrentDb.Properties("AppTitle")
Resume Exit_AddAddressToEnvelope
End Sub
This vba code works exactly as it should when the sub form is opened on its
own, without the switchboard but when the project is opened up without using
the shift key and the switchboard opens, the vba code cant find all the
variables eg Forms!sbfrmSwitchboardCustomers.PostCode"
Any ideas anyone, please.