G
Guest
Hi All,
I found an example of a databse on the internet that does what I am trying
to achieve. That is:
Add several records to a form, when a new form is created.
When I place the exact same code in my database it crashes on the line:
Dim db AS Database.
But when I modify the downloaded database with my tables it works how I want
it to work.
This is the database I downloaded:
http://www.techonthenet.com/access/forms/subform_data.htm
and this is the code:
Private Sub Form_AfterInsert()
Dim db As Database
Dim LSQL As String
Dim LCntr As Integer
'Establish connection to current database
Set db = CurrentDb()
LCntr = 1
'Create SQL to insert item_numbers 1 to 24
Do Until LCntr > 22
LSQL = "insert into inventory_details (StudyNum, StageID)"
LSQL = LSQL & " values ("
LSQL = LSQL & "'" & StudyNum & "', " & LCntr & ")"
'Perform SQL
db.Execute LSQL
'Increment counter variable
LCntr = LCntr + 1
Loop
'Requery subform that new records are listing
inventory_details_Subform.Requery
End Sub
Any ideas or explanations of the code (my VB is limited)
Thanks Brian
I found an example of a databse on the internet that does what I am trying
to achieve. That is:
Add several records to a form, when a new form is created.
When I place the exact same code in my database it crashes on the line:
Dim db AS Database.
But when I modify the downloaded database with my tables it works how I want
it to work.
This is the database I downloaded:
http://www.techonthenet.com/access/forms/subform_data.htm
and this is the code:
Private Sub Form_AfterInsert()
Dim db As Database
Dim LSQL As String
Dim LCntr As Integer
'Establish connection to current database
Set db = CurrentDb()
LCntr = 1
'Create SQL to insert item_numbers 1 to 24
Do Until LCntr > 22
LSQL = "insert into inventory_details (StudyNum, StageID)"
LSQL = LSQL & " values ("
LSQL = LSQL & "'" & StudyNum & "', " & LCntr & ")"
'Perform SQL
db.Execute LSQL
'Increment counter variable
LCntr = LCntr + 1
Loop
'Requery subform that new records are listing
inventory_details_Subform.Requery
End Sub
Any ideas or explanations of the code (my VB is limited)
Thanks Brian