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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert into from main form and subform

Status
Not open for further replies.

TaylorTot

Technical User
Dec 23, 2003
96
US
Hello,

I have a main form (frmMain) that holds the field (cboAssetNumber) and a subform (fsubbrokers) that holds the field (VendorID). The subform has an "Assign" command button. When this is clicked I want it to update the table tblVendorAssignment. This is the code I have.

Code:
  DoCmd.RunSQL "INSERT INTO tblVendorAssignment   (AssignDate, VendorID, AssetNumber) VALUES (#" & Format(Me.txtcurrdate, "mm/dd/yyyy") & "#, '" & Me.txtVendorID & "', '" & Me.frmMain.cboAssetNumber & "')"

I am able to update the table with the vendorId and date, but cannot figure out how to update the main form (cboAssetnumber) to the table

Thanks for your help!
 
When refering to the parent form use:

Me.parent.cboAssetNumber

Cheers,
Bill
 
It does not append the assetnumber because of a type conversion failure. Any ideas? Thank you for your help!
 
If you step through your code it will show you the portion that is throwing the error. The type conversion is like passing a string to an Integer

Dim iNumber as integer
Dim a as string
a = "1" 'still a string
iNumber = "a" 'Should throw an error

iNumber = CInt("a") would convert the string value of a to an integer as long as the value you are trying to convert is numeric in nature
 
Okay I got that to work, thank you both for your help. Can you apply the same logic to updating a table via radio/option buttons?
 
Radio button, checkbox, command button, grids etc. all have events. You can place any code inside the events (Click, double click, change, keypress etc.) to do work, set values etc. Look at your radio button events and decide where and what you want to do there.
 
Is there a way to populate the Me.parent.cboAssetNumber in a second subform. Right now I have the following code:

Code:
      DoCmd.RunSQL "INSERT INTO tblVendorAssignment   (SkipDate, VendorID, AssetNumber, SkipReason) VALUES (#" & Format(Me.txtcurrdate, "mm/dd/yyyy") & "#, '" & Me.txtVendorID & "', '" & Me.Parent.cboAssetNum & "','Slow Response')"

and I get the following error:

The expression you entered has an invalid reference to the parent property

Again thank you :)
 
Not sure what you are now trying to do. Run the SQL statement from a 2nd subform? Insert the results into a 2nd subform? View the results in a 2nd subform? Please clarify a bit.

THanks,Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top