WayneRyan said:
y,
Didn't mean to preface it with "rst": !rst.Fields(myString)
Don't need the rst (Using With)
Is myString set to "Division"?
Is Division a field in the table?
Does !.Fields("Division") work?
Wayne
!.Fields("Division") or !.Fields(Division)
Expected: Identifier or Bracketed expression
!Fields(Division)
"Item not found in this collection"
What I am trying to do is the following.
I have a table that is year, quarter, division, label1, label2, label3
Now I have unbound textboxes (with the same names)
When I update a textbox, it writes that value to the table, then accumulates the same value and gives the total to a parent object.
Now I figured instead of doing the same code 20 times, I would pass the control through a function and do it that way.
On Error GoTo Err_AppMeetsNo_AfterUpdate
thename = "AppMeetsNo" 'Name of the textbox, also name of the field
updatedata (thename) 'Sends that name through to the function
Exit_AppMeetsNo_AfterUpdate:
Exit Sub
Err_AppMeetsNo_AfterUpdate:
MsgBox Err.Description
Resume Exit_AppMeetsNo_AfterUpdate
Function updatedata(thename)
On Error GoTo Err_updatedata
Pert = DLookup("Pertain", "miscindicators", "division = '" & Division & "' AND year = '" & year & "' AND quarter = '" & Quarter & "'")
If IsNull(Pert) = True Then
Pert = DLookup("Pertain", "program", "program = '" & Division & "'")
End If
If IsNumeric(Me.Controls(thename)) = False And Me.Controls(thename) <> "" And IsNull(Me.Controls(thename)) = False Then
Me.Controls(thename) = DLookup(thename, "miscindicators", "[Year] = '" & year & "' AND [Quarter] = '" & Quarter & "' AND [Division] = '" & Division & "'")
End If
check = DLookup("Division", "miscindicators", "Year = '" & year & "' And Quarter ='" & Quarter & "' AND Division = '" & Division & "'")
Set rst = CurrentDb.OpenRecordset("SELECT * FROM miscindicators WHERE Year = '" & year & "' And Quarter ='" & Quarter & "' AND Division = '" & Division & "';")
With rst
If IsNull(check) = True Then
.AddNew
Else
.Edit
End If
![year] = year
![Quarter] = Quarter
![Division] = Division
!Fields(thename) = Me.Controls(thename) '!!!HELP HERE!!!
![Pertain] = Pert
.Update
End With
Do While 1 = 1
Count = DLookup("sum(" & thename & ")", "miscindicators", "Year = '" & year & "' And Quarter ='" & Quarter & "' AND Pertain = '" & Pert & "' AND isNull(AppMeetsNo) = False")
Total = DLookup("count(" & thename & ")", "miscindicators", "Year = '" & year & "' And Quarter ='" & Quarter & "' AND Pertain = '" & Pert & "' AND isNull(AppMeetsNo) = False")
check = DLookup("Division", "miscindicators", "Year = '" & year & "' And Quarter ='" & Quarter & "' AND Division = '" & Pert & "'")
Set rst = CurrentDb.OpenRecordset("SELECT * FROM miscindicators WHERE Year = '" & year & "' And Quarter ='" & Quarter & "' AND Division = '" & Pert & "';")
With rst
If IsNull(check) = True Then
.AddNew
Else
.Edit
End If
![year] = year
![Quarter] = Quarter
![Division] = Pert
!Fields(thename) = Me.Controls(thename) '!!!HELP HERE!!!
pertainto = DLookup("pertain", "program", "program = '" & Pert & "'")
![Pertain] = pertainto
.Update
End With
Pert = DLookup("Pertain", "miscindicators", "division = '" & Pert & "' AND year = '" & year & "' AND quarter = '" & Quarter & "'")
If IsNull(Pert) = True Then
Pert = DLookup("Pertain", "program", "program = '" & Pert & "'")
End If
If IsNull(Pert) = True Or Pert = "None" Then
Exit Do
End If
Loop
Exit_updatedata:
Exit Function
Err_updatedata:
MsgBox Err.Description
Resume Exit_updatedata