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

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
 
M

Mike Painter

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
 
A

ad

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
 

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