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

using ADO to add new record from form AND subform

Status
Not open for further replies.

jalgier

Programmer
Nov 7, 2001
15
US
Greetings,

I have an unbound form in which there is an subform. I used ADO to sucessfully add a new record to a table, but I'm not sure how to get the subform's record(s) to write to its table. My code is as follows...

Private Sub cmdSubmit_Click()
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
With rst
.ActiveConnection = CurrentProject.Connection
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "Ticket" 'table name
.AddNew
![Ticket No] = Me.Ticket_No
!TicketDate = Me.TicketDate
!PO = Me.PO '...the fields continue on for a while
.Update
.Close
End With

The subform is linked to the master form by TicketNo. These records would need to write to the TicketDetails table as opposed to the Ticket table. How would I do this in the same fell swoop? Or would it be better/easier to do an SQL statement? Thanks in advance.

 

simply open another recordset
.Open "Ticketdetails table" 'table name
.AddNew
![Ticket No] = Me.Ticket_No
!TicketDate = Me.TicketDate
!PO = Me.PO '...the fields continue on for a while
.Update
.Close
 
Thanks, that worked...but here is the other problem I am having. The subform I have is set to datasheet view, but when a new record is started, the subform does not create any other records. Basically, you can only enter one record from the subform instead of multiple records. What do I need to do so I can have multiple records on the subform associated with the main form?

FYI, the subform is unbound (which may be the problem).
Also, assuming I continue to use the code above, I need to make sure the code loops through each record (in the subform). What would be the best way to accomplish that?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top