How do I add record to a sub form with code?

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

I would like to add new record to a subform using code. This is what I tried:

DoCmd.GoToRecord acDataForm, "Me.Special_requirements_subform", acNewRec
Me.Special_requirements_subform![Category] = "Motor related"
Me.Special_requirements_subform![Special Requirement] = "Special motor: " & Me.MCode1 & " + " & Me.MCode2


Obviously it didn't work. Can any body tell me the appropriate way to do this? Thanks in advance.

ad
 
ad said:
I would like to add new record to a subform using code. This is what I tried:

DoCmd.GoToRecord acDataForm, "Me.Special_requirements_subform", acNewRec
Me.Special_requirements_subform![Category] = "Motor related"
Me.Special_requirements_subform![Special Requirement] = "Special
motor: " & Me.MCode1 & " + " & Me.MCode2INSERT INTO is hard to find in help but it's there.
Here's a sample.


Public Sub AddSQLRecord(CLID, SD, ED, BFID, BUnits, invoicenum)
strSQL = "INSERT INTO billdone (ClientID , StartDate , StopDate ,
BillForID, Billingunits, invoicenumber ) VALUES ( '"
strSQL = strSQL & CLID & "', '" & SD & "', '" & ED & "', '" & BFID & "', '"
& BUnits & "', '" & invoicenum & "')"
' MsgBox strSQL
DoCmd.RunSQL strSQL
 
Mike Painter said:
ad said:
I would like to add new record to a subform using code. This is what I tried:

DoCmd.GoToRecord acDataForm, "Me.Special_requirements_subform", acNewRec
Me.Special_requirements_subform![Category] = "Motor related"
Me.Special_requirements_subform![Special Requirement] = "Special
motor: " & Me.MCode1 & " + " & Me.MCode2INSERT INTO is hard to find in help but it's there.
Here's a sample.


Public Sub AddSQLRecord(CLID, SD, ED, BFID, BUnits, invoicenum)
strSQL = "INSERT INTO billdone (ClientID , StartDate , StopDate ,
BillForID, Billingunits, invoicenumber ) VALUES ( '"
strSQL = strSQL & CLID & "', '" & SD & "', '" & ED & "', '" & BFID & "', '"
& BUnits & "', '" & invoicenum & "')"
' MsgBox strSQL
DoCmd.RunSQL strSQL

Thanks Mike
It IS bit hard to find, actually I still havn't found it in the Help.
But I did as you told. It works perfectly. Here is my code:

strSQL = "INSERT INTO Special_requirements ([Unit ID] ,Category , SpecialItem ) VALUES ( "
strSQL = strSQL & Me.[Unit ID] & ", 'Moter related', 'Special motor: " & Me.MCode1 & " + " & Me.MCode2 & "')"
'MsgBox strSQL
DoCmd.RunSQL strSQL


Thankd again.Now I know how to do this profesionally ^_^

ad
 
Back
Top