I am getting the above error trying to take an data from one listbox and copying it into a field in another listbox.
The first listbox is bound to a table of addresses. The second is a listbox of quotes. In theory there should be a one-to-many relationship but this was originally 2 tables from 2 seperate databases. I am doing a data cleanup operation using this method so that i can begin to restructure the whole database.
This is the code i have:
Private Sub btnLink_Click()
On Error GoTo Err_btnLink_Click
Dim i As Variant
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim qd As DAO.QueryDef
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("qryQuotes")
For Each i In Me.listQuotes.ItemsSelected
rst.Edit
rst!AID = Me.listAddresses
rst.Update
rst.MoveNext
Next i
Me.listQuotes.Requery
Set rst = Nothing
Set qd = Nothing
Exit_btnLink_Click:
Exit Sub
Err_btnLink_Click:
MsgBox Err.Number & " " & Err.Description
Resume Exit_btnLink_Click
End Sub
I believe the line in red is causing the error.
The code also does not work correctly as it is not copying the ID from the left table to the selected records in the right table.
Could anyone help with this 2 problems, it would be much appreciated.
Thanks all
P.S. Form attached
The first listbox is bound to a table of addresses. The second is a listbox of quotes. In theory there should be a one-to-many relationship but this was originally 2 tables from 2 seperate databases. I am doing a data cleanup operation using this method so that i can begin to restructure the whole database.
This is the code i have:
Private Sub btnLink_Click()
On Error GoTo Err_btnLink_Click
Dim i As Variant
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim qd As DAO.QueryDef
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("qryQuotes")
For Each i In Me.listQuotes.ItemsSelected
rst.Edit
rst!AID = Me.listAddresses
rst.Update
rst.MoveNext
Next i
Me.listQuotes.Requery
Set rst = Nothing
Set qd = Nothing
Exit_btnLink_Click:
Exit Sub
Err_btnLink_Click:
MsgBox Err.Number & " " & Err.Description
Resume Exit_btnLink_Click
End Sub
I believe the line in red is causing the error.
The code also does not work correctly as it is not copying the ID from the left table to the selected records in the right table.
Could anyone help with this 2 problems, it would be much appreciated.
Thanks all
P.S. Form attached