air1access
Technical User
Ok - I have a form, with a combo box.
The combo box contains "Jan-2015", Feb-2015", etc.
I have a table with field names "Agent_SAN", "Jan-2015", Feb-2015", etc.
I want the user to be able to select a month-year from the combo box, then update that matching column/field in the table...
The table has a ID field - Agent_SAN to link too - so I need to loop the records, find a match on Agent_SAN, and update the field that was selected from the combo box...
Sure hope this makes sense..!!
Below is what I'm working with...
I have been able to get to loop through the field names, and find the match per the combo box but I am lost as to how to get the selected field updated...
Any suggestions/ideas would be super appreciated..!!!
-----------------------------------------------------------------
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim rstBase As DAO.Recordset
Dim rstVarying As DAO.Recordset
Set db = CurrentDb
Set tdf = db.TableDefs("Monthly_GT3_MainCounts")
Set rstBase = db.OpenRecordset("Monthly_GT3_MainCounts", dbOpenDynaset)
Set rstVarying = db.OpenRecordset("Agent_PreviousMonth_Counts", dbOpenDynaset)
For Each fld In tdf.Fields
If fld.Name = Me!cboMonthDate Then
rstVarying.MoveFirst
Do Until rstVarying.EOF
rstBase.FindFirst "[Agent_SAN] = " & "'" & rstVarying!Agent_SAN & "'"
If Not rstBase.NoMatch Then
rstBase.Edit
fld.Name = Nz(rstVarying!PreviousMonth_Count, 0)
rstBase.Update
End If
rstVarying.MoveNext
Loop
End If
Next fld
The combo box contains "Jan-2015", Feb-2015", etc.
I have a table with field names "Agent_SAN", "Jan-2015", Feb-2015", etc.
I want the user to be able to select a month-year from the combo box, then update that matching column/field in the table...
The table has a ID field - Agent_SAN to link too - so I need to loop the records, find a match on Agent_SAN, and update the field that was selected from the combo box...
Sure hope this makes sense..!!
Below is what I'm working with...
I have been able to get to loop through the field names, and find the match per the combo box but I am lost as to how to get the selected field updated...
Any suggestions/ideas would be super appreciated..!!!
-----------------------------------------------------------------
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim rstBase As DAO.Recordset
Dim rstVarying As DAO.Recordset
Set db = CurrentDb
Set tdf = db.TableDefs("Monthly_GT3_MainCounts")
Set rstBase = db.OpenRecordset("Monthly_GT3_MainCounts", dbOpenDynaset)
Set rstVarying = db.OpenRecordset("Agent_PreviousMonth_Counts", dbOpenDynaset)
For Each fld In tdf.Fields
If fld.Name = Me!cboMonthDate Then
rstVarying.MoveFirst
Do Until rstVarying.EOF
rstBase.FindFirst "[Agent_SAN] = " & "'" & rstVarying!Agent_SAN & "'"
If Not rstBase.NoMatch Then
rstBase.Edit
fld.Name = Nz(rstVarying!PreviousMonth_Count, 0)
rstBase.Update
End If
rstVarying.MoveNext
Loop
End If
Next fld