BlahBlahBlah
Registered User.
- Local time
- Tomorrow, 04:55
- Joined
- Sep 15, 2011
- Messages
- 17
Hi.
I have implemented functionality that lets the user import data from an Excel spreadsheet into the Access tables in my database. As an example, the user can import many Rules records from a spreadsheet after they've chosen which Overview the Rules records are associated with. The data is stored in a temporary table that has the same structure as the real table, sans the primary key ID field, to allow preview/editing before importing. Once the user has clicked Import, this code is run:
This works fine, but I need to insert a relationship pair (OverviewID, RulesID) into a relationship table for each Rules record the user imports. Each Overview can have 0 to many Rules associated with it.
So what would be the best way to handle this? I'd probably need to insert one record into the Relationship table after every Rule is inserted, I'm guessing. Usually I'd let a form handle this, but I don't think there's a way to automate it.
Oh, and both the Rules and Overview tables have an AutoNumber as their ID field if that helps, with the Relationship table containing only two Number fields.
Cheers.
Edit: I realised I could probably use a recordset instead of the Execute function, will try that out.
I have implemented functionality that lets the user import data from an Excel spreadsheet into the Access tables in my database. As an example, the user can import many Rules records from a spreadsheet after they've chosen which Overview the Rules records are associated with. The data is stored in a temporary table that has the same structure as the real table, sans the primary key ID field, to allow preview/editing before importing. Once the user has clicked Import, this code is run:
Code:
Private Sub importBtn_Click()
Dim sqlQuery As String
sqlQuery = "INSERT INTO " & getCorrectDestinationTableName & " (" & _
getTableFieldNames(getCorrectDestinationTableName) & ")" & _
" SELECT * FROM " & getCorrectPreviewTableName & ";"
CurrentDb.Execute sqlQuery
End Sub
So what would be the best way to handle this? I'd probably need to insert one record into the Relationship table after every Rule is inserted, I'm guessing. Usually I'd let a form handle this, but I don't think there's a way to automate it.
Oh, and both the Rules and Overview tables have an AutoNumber as their ID field if that helps, with the Relationship table containing only two Number fields.
Cheers.
Edit: I realised I could probably use a recordset instead of the Execute function, will try that out.
Last edited: