View Full Version : Add a record to a subform


TomBP
07-07-2006, 02:43 AM
http://i54.photobucket.com/albums/g115/TomBP/Pic1-1.jpg

As you can see I have a form with a subform in it. What I want to achieve is that when I press add new record a blank record will popup in the subform without all the other records you currently see. An example of this is the picture under this.

http://i54.photobucket.com/albums/g115/TomBP/Pic2-1.jpg

If I then fill in the new record row the record will be added to the main table.

I already tried it for myself but the problem that occurs with my macro is the following:

http://i54.photobucket.com/albums/g115/TomBP/Pic3.jpg

The macro has the following design:

http://i54.photobucket.com/albums/g115/TomBP/Pic4.jpg

How can I add a new record without opening the subform?

clerics
07-10-2006, 01:50 AM
Use query or SQL to solve your problem .
Something like this

strSql = "INSERT INTO YourTBL (Firma,Factuurnummer,maand,Soort,Transport,Product )" & _
" SELECT [Forms]![YourFormName]![Firma] AS S1,[Forms]![YourFormName]![Factuurnummer] AS S2,[Forms]![YourFormName]![maand] AS S3,[Forms]![YourFormName]![Soort] AS S4,[Forms]![YourFormName]![Transport] AS S5,[Forms]![YourFormName]![Product] AS S6;"

Me.Refresh
DoCmd.RunSQL (strSql)
Me.SubFormName.requery

TomBP
07-10-2006, 04:21 AM
Thx for your reply but I got it working using this:

I put this behind "Add New Record" in the OnClick event.

Me.frmSubform.SetFocus
Me.fromSubform.Form.Firma.SetFocus
DoCmd.GoToRecord , , acNewRec