Boreal2009
Registered User.
- Local time
- Today, 09:15
- Joined
- Oct 5, 2009
- Messages
- 10
Hi Everyone,
I'm hoping someone out there can help me with this. I have found a great example on the web that provides code on how to autopopulate data in a subform based on info entered in the main form. This example is written for Access 2000 and when I try to use it in Access 2003 I keep getting errors. I have tried playing around with the code but I don't have much experience here and as such I have not been able to solve the errors. I was hoping someone out there could look at the example for me and make the appropriate changes to the code so it will work in 2003.
Here is the link to the example: http://www.techonthenet.com/access/forms/subform_data.php
And here is the code in question:
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 > 24
LSQL = "insert into inventory_details (serial_number, item_number)"
LSQL = LSQL & " values ("
LSQL = LSQL & "'" & serial_number & "', " & LCntr & ")"
'Perform SQL
db.Execute LSQL
'Increment counter variable
LCntr = LCntr + 1
Loop
'Requery subform that new records are listing
frmInventory_details.Requery
End Sub
Private Sub Command9_Click()
On Error GoTo Err_Command9_Click
DoCmd.GoToRecord , , acNewRec
Exit_Command9_Click:
Exit Sub
Err_Command9_Click:
MsgBox Err.Description
Resume Exit_Command9_Click
I'm hoping someone out there can help me with this. I have found a great example on the web that provides code on how to autopopulate data in a subform based on info entered in the main form. This example is written for Access 2000 and when I try to use it in Access 2003 I keep getting errors. I have tried playing around with the code but I don't have much experience here and as such I have not been able to solve the errors. I was hoping someone out there could look at the example for me and make the appropriate changes to the code so it will work in 2003.
Here is the link to the example: http://www.techonthenet.com/access/forms/subform_data.php
And here is the code in question:
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 > 24
LSQL = "insert into inventory_details (serial_number, item_number)"
LSQL = LSQL & " values ("
LSQL = LSQL & "'" & serial_number & "', " & LCntr & ")"
'Perform SQL
db.Execute LSQL
'Increment counter variable
LCntr = LCntr + 1
Loop
'Requery subform that new records are listing
frmInventory_details.Requery
End Sub
Private Sub Command9_Click()
On Error GoTo Err_Command9_Click
DoCmd.GoToRecord , , acNewRec
Exit_Command9_Click:
Exit Sub
Err_Command9_Click:
MsgBox Err.Description
Resume Exit_Command9_Click