Hi Jenn
Objective said:
create a record in 2 tables
To follow up on
Aerin's post, you need to populate your query. Since your info is a little sparse, specifics can not be provided.
After you have created the APPEND query with Query Builder - it is okay to fudge some numbers so you can simulate an insert record event. Switch the view for Query Builder to SQL. (from menu, "View" -> "SQL View") Cut and paste the SQL statement into the code responsible for "Repeat".
The SQL statement will be displayed in red because you have broken a rule or two for VBA. Don't panic.
Add the lines...
Code:
Dim strSQL as String
'this line should appear near the top of the sub routine
strSQL = " " 'add your SQL statment between the double quotes
'from Aerin post
docmd.SetWarning False
'run the query
docmd.OpenQuery strSQL
'don't forget to turn warnings back
docmd.SetWarnings True
BUT, there is one more step. You need to reference the text boxes on the form / subform1, and substitute this information in your query.
Here is an example based on the following assumptions...
Me.textboxString1 - text string in a textbox on main form
Me.textboxDate2 - date in a textbox on main form
Me.textboxNumber3 - number in a textbox on main form
Me.YourSubForm.Form.textboxNumber4 - number in text box on subform
Code:
Dim strSQL as String, strQ as String
strQ = Chr$(34)
strSQL = "INSERT Into YourTable (YourText1, YourDate2, YourNumber3, YourNumber4) " _
& "Values (" & strQ & Me.textboxString1 & strQ & ", #" & Me.textboxDate2 _
& "#, " & Me.textboxNumber3 & ", " & Me.YourSubForm.Form.textboxNumber4 & ")"
Note:
& - joins string and variables together.
_ - used to wrap text onto the subsequent line
" - string variables must be encapsulated with quotes. My approach is to use strQ (assigned the character code 34 = "). Other approaches is to use """ (double quote within double quotes), and "'" (single quote within double quote)
Using a DAO approach, same assumptions...
Code:
Dim dbs as DAO.Database, rst as DAO.Recordset
Set dbs = CurrentDB()
Set rst = dbs.OpenRecorset("YourTable")
With rst
.AddNew
!YourText1 = Me.textboxString1
!YourDate2 = Me.textboxDate2
!YourNumber3 = Me.textboxNumber3
!YourNumber4 = Me.YourSubForm.Form.textboxNumber4
.Update
End With
rst.Close
dbs.Close
Depending on your data, you would use a similar approach to update the second table per your objectives.
Hope this gives you enough ideas on how you can handle your problem.
Richard