NeedsHelp101
Technical User
Hi,
I'm very new to VBA and I was hoping someone could help:
I'm running a For Each loop through values stored in the temporary table (working) and storing them into a permanent table (tblTrafficForForm).
The working table is populated from the form, and three columns (open, close, and market) in the permanent table are populated from two textboxes, and a multiselect list box (lstMarket), respectively, in the form.
The goal is to assign all the data in the working table to each open-close-market combination.
I bolded the problems I'm having with the code. Any help would be greatly appreciated!!
I'm very new to VBA and I was hoping someone could help:
I'm running a For Each loop through values stored in the temporary table (working) and storing them into a permanent table (tblTrafficForForm).
The working table is populated from the form, and three columns (open, close, and market) in the permanent table are populated from two textboxes, and a multiselect list box (lstMarket), respectively, in the form.
The goal is to assign all the data in the working table to each open-close-market combination.
Code:
Dim dbMarketing As Database
Dim FMarket As Variant
Dim rec As RecordSet
Dim working
Set dbMarketing = CurrentDb()
Set rec = dbMarketing.OpenRecordset("tblTrafficForForm")
Set working = dbMarketing.OpenRecordset("working")
working.MoveFirst
For Each FMarket In Me.lstMarket.ItemsSelected
rec.AddNew
[b]'Not sure if referencing is correct[/b]
rec!Col1 = Me.boxCol1.Value
rec!Col2 = Me.boxCol2.Value
rec!market = Me.lstMarket.ItemData(FMarket)
rec!Col4 = working.boxCol4.Value
rec!Col5 = working.lstCol5.Value
rec!Col6 = working.lstCol6.Value
rec!Col7 = working.lstCol7.Value
rec!Col8 = working.lstCol8.Value
rec!Col9 = working.txtCol9.Value
rec!Col10 = working.lstCol10.Value
rec.Update [b]'Here i get the error: Object invalid or no longer set[/b]
Next FMarket
rec.Close
working.MoveNext
'I used Col4 here bc there should always be a value in it
If IsNull(working!Col4) Then
working.Clear [b]'is this correct to empty the table?[/b]
[b] 'Is there a way to refresh the subform so it can be reused for entry of the next data set?[/b]
Else: GoTo begin
End If
Set rec = Nothing
Set dbMarketing = Nothing
Set working = Nothing
I bolded the problems I'm having with the code. Any help would be greatly appreciated!!