puzzledinsc
Programmer
Reference Shannon88, This is a similar problem. I have an employee database and the user wants to be able to archive a record from time to time after a promotion, etc. So I'm trying to take the record in the form and write it to another table (archive_emp) at the push of a button. The tables are on a SQL server connected by an ODBC driver in Access. I'm using the following code and what happens is that it prompts me for the local variables (insted of lifting them off the Me! form), then it gives me an error that it can't open the output table - archive_emp. I seem to be missing a fundamental grasp on writing from one table to another in Access.
Code:
Private Sub Archive_Record_Click()
On Error GoTo Err_Archive_Record_Click
Dim l_emp_id, l_last_name, l_first_name As String
Dim db As Database
l_emp_id = Me.EMP_ID
l_last_name = Me.LAST_NAME
l_first_name = Me.FIRST_NAME
Set db = CurrentDb
DoCmd.RunSQL "insert into archive_emp (emp_id, last_name, first_name) values (l_emp_id, l_last_name, l_first_name)"
Exit_Archive_Record_Click:
Exit Sub
Err_Archive_Record_Click:
MsgBox Err.Description
Resume Exit_Archive_Record_Click
End Sub
PS: I tried to change Dim db as DataBase to AcDataObjectType but it failed at Set db = Current and said "Object required"
Thanks
Code:
Private Sub Archive_Record_Click()
On Error GoTo Err_Archive_Record_Click
Dim l_emp_id, l_last_name, l_first_name As String
Dim db As Database
l_emp_id = Me.EMP_ID
l_last_name = Me.LAST_NAME
l_first_name = Me.FIRST_NAME
Set db = CurrentDb
DoCmd.RunSQL "insert into archive_emp (emp_id, last_name, first_name) values (l_emp_id, l_last_name, l_first_name)"
Exit_Archive_Record_Click:
Exit Sub
Err_Archive_Record_Click:
MsgBox Err.Description
Resume Exit_Archive_Record_Click
End Sub
PS: I tried to change Dim db as DataBase to AcDataObjectType but it failed at Set db = Current and said "Object required"
Thanks