accessing a subform

G

Guest

I have a form A where I have a command button that needs to open Form B.
Form B has a subform C on it in datasheet view. I need the command button to
also add a new record into subform c. I keep trying to get it to do that but
is says it can't find my subform. Form B opens just fine, but anytime I try
to go any further with writing code to add a new record, it keeps adding the
new record to form B instead of form C. How do I correctly call subform C?
Thanks!
 
A

Arvin Meyer [MVP]

The proper syntax for addressing a subform is:

Forms!FormName!SubformControlName.Form!ControlName

On your form that would be:

Forms!FormB!SubformC.Form!txtIDField

The SubformControlName is not necessarily the same as the name of the
subform. Look at the Name property in your form's property sheet for the
correct one.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
G

Guest

From FormA on the open form command line pass an openargs
DoCmd.OpenForm "FormB", , , , , , "AddNewRecord"

On the on load event of FormB Write the code
If Me.OpenArgs = "AddNewRecord" Then
Me.SubFormC.SetFocus
DoCmd.GoToRecord , , acNewRec
End If
 
G

Guest

Okay, what it's doing is writing over existing records rather than adding it
as a new record. The subform is in dataSHEET view & I need all the records
for that account to show up so the user will know whether or not they really
want to "commit" this record as it stands. They may need to "tweak" it, if
the customer has a credit balance or whatever. Somehow I have to get it to
go to a new record without it going into DataENTRY view.

Here's the code I have so far:
Dim stLinkCriteria As String, form1 As String, form2 As String
Dim form3 As String, form4 As String, qry As String

form1 = "frmAccount"
form2 = "frmTransaction"
form3 = "frmCustomer"
form4 = "frmCustomerTourDataEntry"
stLinkCriteria = "[CID]=" & Me![CID]

'Saves current record in tblCustomerTour
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

'Opens account form to current customer
DoCmd.OpenForm form1, , , stLinkCriteria
'DoCmd.GoToRecord , , acNewRec
Forms!frmAccount!frmTransaction.Form![TID] =
Form_frmCustomerTourDataEntry.TID
Forms!frmAccount!frmTransaction.Form![Type] = "Charge"
Forms!frmAccount!frmTransaction.Form![Charge-DR] =
Form_frmCustomerTourDataEntry.CustomerPrice

Right now the line that adds a new record is commented out because it's
opening in DATAENTRY mode, not showing all the other records that need to be
shown so that the Account BALANCE text box on the parent form contains the
correct amount (it's a calculated figure based on the entries in the
transaction subform)
Thanks in advance for your help!
 

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