calling data from main form

M

Mark J Kubicki

I'm adding a record at a subform to a table which requires some data from
the main (calling) form; however,
the (2) fields of data on the main form are being returned as having no
value (although they do)


Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("FixtureCatalogueCostHistory", dbOpenDynaset)
With rst
..AddNew
!Date = datDate
!Manufacturer = Me.Manufacturer 'data being called from main form
!CatalogNumber = Me.CatalogNumber 'data being called from main form
!Amount = txtAmount
!Source = txtSource
!CostType = txtCostType
!note = txtNote
!Author = txtAuthor
..Update
End With

any suggestions would be a great help, thanks in advance,
mark
 
J

John W. Vinson

I'm adding a record at a subform to a table which requires some data from
the main (calling) form; however,
the (2) fields of data on the main form are being returned as having no
value (although they do)


Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("FixtureCatalogueCostHistory", dbOpenDynaset)
With rst
.AddNew
!Date = datDate
!Manufacturer = Me.Manufacturer 'data being called from main form
!CatalogNumber = Me.CatalogNumber 'data being called from main form
!Amount = txtAmount
!Source = txtSource
!CostType = txtCostType
!note = txtNote
!Author = txtAuthor
.Update
End With

If this code is in a Subform event, then Me. refers *to the subform*.
Use Parent!Manufacturer and Parent!CatalogNumber instead.

John W. Vinson [MVP]
 
A

Al Campagna

Mark,
Regarding addressing the values on the main form... John Vinson's solution has that
covered.

But, I'm questioning why you need to "capture" values from the Main form to the Subform
at all. If the Main and Sub are properly related (Parent to Child) via a legitimate
unique key field, you should never have to capture those "main" values to the sub.
Because they are related... you can always re-associate any subform record to the
appropriate Manufacturer and CatalogNumber in any subsequent form, query, or report.
In other words... given ANY subform record (with no Manufacturer or Catalog value field
at all) ... you should be able to determine, through the realtionship, the Manufacturer
and CatalogNumber.
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 

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