All, I have a query that runs thru and add agents to several dif tables; at least that is what it should do. Right now I am stumbling over how to add a value to a certain field of the rsTbl.
Desc:
the user selects a month from a combo on the form and enters some other info needed and clicks a cmdbutton
this then does the following...
Function AgentADD()
'first we will add to the Agent Table
Set rsTbl = CurrentDb.OpenRecordset("tbl-Agents")
ANtemp = "'" & Trim(Forms("frm-AgentADD")![txtAgentName].Value) & "'"
AIDtemp = "'" & Trim(Forms("frm-AgentADD")![txtAgentID].Value) & "'"
If ANtemp = "''" Or AIDtemp = "''" Or Len(AIDtemp) <> 7 Or Forms("frm-AgentADD")![Text27].Value = "Amount" Then 'if no name or id or if the id is not 5 true characters
MsgBox "You must enter an Agents Name and his/her ID " & vbCrLf & _
"and an Idividual Goal amount. Please try again " & vbCrLf & _
"and include all required information.", vbOKOnly, "Need More Info."
Else 'user typed in a name and id that matches needed criteria
rsTbl.AddNew
rsTbl![Location] = Forms("frm-AgentADD")![txtLocation].Value
rsTbl![AgentID] = Forms("frm-AgentADD")![txtAgentID].Value
rsTbl![AgentName] = Forms("frm-AgentADD")![txtAgentName].Value
rsTbl![SupervisorID] = Forms("frm-AgentADD")![txtSupervisorID].Value
rsTbl![SupervisorName] = Forms("frm-AgentADD")![txtSupervisor].Value
rsTbl![Dept/Bucket] = Forms("frm-AgentADD")![txtDept].Value
If Forms("frm-AgentADD")![cmbTraining].Value = "Yes" Then
rsTbl![C&RTraining] = "Y"
Else
rsTbl![C&RTraining] = "N"
End If
If Forms("frm-AgentADD")![cmbProbation].Value = "Yes" Then
rsTbl![Probation] = "Y"
Else
rsTbl![Probation] = "N"
End If
If Forms("frm-AgentADD")![Combo36].Value = "Yes" Then
rsTbl![Team/Individual] = "T" 'signals a team goal
Else
rsTbl![Team/Individual] = "I" 'signals only an idividual goal. not done prior to self help; all were labeled as T
End If
If Forms("frm-AgentADD")![Combo44].Value = "Yes" Then
rsTbl![LoanLoss] = "Y"
Else
rsTbl![LoanLoss] = "N"
End If
If Forms("frm-AgentADD")![Combo45].Value = "Yes" Then
rsTbl![TeamMultiplier] = "Y"
Else
rsTbl![TeamMultiplier] = "N"
End If
Dim iSend As Integer
iSend = MsgBox("You are about to add " & Forms("frm-AgentADD")![txtAgentName] & vbCrLf & _
"to the active agent list? Is this correct", vbYesNo, "Update Yes/No")
If iSend = 6 Then 'user selected Yes
On Error GoTo Err_Update
rsTbl.update 'this finishes the Agent Table update
'need to update the individual dlq goal table which everyone has
Call Update_IndDlq_Goal
MsgBox "You have successfully added " & Forms("frm-AgentADD")![txtAgentName] & vbCrLf & _
"to the list of active agents."
DoCmd.Close acForm, "frm-AgentADD", acSaveNo
DoCmd.OpenForm "frm-AgentADD"
Else
MsgBox "No records were updated", vbOKOnly, "No Update"
Exit Function
Err_Update:
MsgBox "Please review your entries; something is invalid. " & vbCrLf & _
"This is normally due to a duplicated Agent ID.", vbOKOnly, "Unable to Update"
End If
End If
End Function
Function Update_IndDlq_Goal()
Dim varRST As String
Set rsTbl = Nothing
If Forms("frm-AgentADD")![cmbDate] = "January" Then
varRST = "rsTbl.Fields(3)"
ElseIf Forms("frm-AgentADD")![cmbDate] = "February" Then
varRST = "rsTbl![02-yyyy]"
ElseIf Forms("frm-AgentADD")![cmbDate] = "March" Then
varRST = rsTbl.Fields(5)
End If
Set rsTbl = CurrentDb.OpenRecordset("DlqGoal(Ind)")
rsTbl.AddNew
rsTbl![Dept/Bucket] = Forms("frm-AgentADD")![txtDept].Value
rsTbl![AgentName] = Forms("frm-AgentADD")![txtAgentName].Value
rsTbl![AgentID] = Forms("frm-AgentADD")![txtAgentID].Value
varRST = Forms("frm-AgentADD")![Text27].Value
rsTbl.update
Set rsTbl = CurrentDb.OpenRecordset("tbl-Agents")
End Function
all code works except for what is colored RED. What I am wanting to do is, depending on the month selected, I want to add a value to that specific field.
The DlqGoal(Ind) table adds the name, dept, and id but no value for field(x)!
My table is set up as
F1= dept/bucket
F2= name
F3=id
F4=01-yyyy
F5=02-yyyy
F6=03-yyyy
so if the user selcts "February" then I want the value to populate in rsTbl![02-yyyy].
Any guesses, suggestions, answers maybe
Thanks
Desc:
the user selects a month from a combo on the form and enters some other info needed and clicks a cmdbutton
this then does the following...
Function AgentADD()
'first we will add to the Agent Table
Set rsTbl = CurrentDb.OpenRecordset("tbl-Agents")
ANtemp = "'" & Trim(Forms("frm-AgentADD")![txtAgentName].Value) & "'"
AIDtemp = "'" & Trim(Forms("frm-AgentADD")![txtAgentID].Value) & "'"
If ANtemp = "''" Or AIDtemp = "''" Or Len(AIDtemp) <> 7 Or Forms("frm-AgentADD")![Text27].Value = "Amount" Then 'if no name or id or if the id is not 5 true characters
MsgBox "You must enter an Agents Name and his/her ID " & vbCrLf & _
"and an Idividual Goal amount. Please try again " & vbCrLf & _
"and include all required information.", vbOKOnly, "Need More Info."
Else 'user typed in a name and id that matches needed criteria
rsTbl.AddNew
rsTbl![Location] = Forms("frm-AgentADD")![txtLocation].Value
rsTbl![AgentID] = Forms("frm-AgentADD")![txtAgentID].Value
rsTbl![AgentName] = Forms("frm-AgentADD")![txtAgentName].Value
rsTbl![SupervisorID] = Forms("frm-AgentADD")![txtSupervisorID].Value
rsTbl![SupervisorName] = Forms("frm-AgentADD")![txtSupervisor].Value
rsTbl![Dept/Bucket] = Forms("frm-AgentADD")![txtDept].Value
If Forms("frm-AgentADD")![cmbTraining].Value = "Yes" Then
rsTbl![C&RTraining] = "Y"
Else
rsTbl![C&RTraining] = "N"
End If
If Forms("frm-AgentADD")![cmbProbation].Value = "Yes" Then
rsTbl![Probation] = "Y"
Else
rsTbl![Probation] = "N"
End If
If Forms("frm-AgentADD")![Combo36].Value = "Yes" Then
rsTbl![Team/Individual] = "T" 'signals a team goal
Else
rsTbl![Team/Individual] = "I" 'signals only an idividual goal. not done prior to self help; all were labeled as T
End If
If Forms("frm-AgentADD")![Combo44].Value = "Yes" Then
rsTbl![LoanLoss] = "Y"
Else
rsTbl![LoanLoss] = "N"
End If
If Forms("frm-AgentADD")![Combo45].Value = "Yes" Then
rsTbl![TeamMultiplier] = "Y"
Else
rsTbl![TeamMultiplier] = "N"
End If
Dim iSend As Integer
iSend = MsgBox("You are about to add " & Forms("frm-AgentADD")![txtAgentName] & vbCrLf & _
"to the active agent list? Is this correct", vbYesNo, "Update Yes/No")
If iSend = 6 Then 'user selected Yes
On Error GoTo Err_Update
rsTbl.update 'this finishes the Agent Table update
'need to update the individual dlq goal table which everyone has
Call Update_IndDlq_Goal
MsgBox "You have successfully added " & Forms("frm-AgentADD")![txtAgentName] & vbCrLf & _
"to the list of active agents."
DoCmd.Close acForm, "frm-AgentADD", acSaveNo
DoCmd.OpenForm "frm-AgentADD"
Else
MsgBox "No records were updated", vbOKOnly, "No Update"
Exit Function
Err_Update:
MsgBox "Please review your entries; something is invalid. " & vbCrLf & _
"This is normally due to a duplicated Agent ID.", vbOKOnly, "Unable to Update"
End If
End If
End Function
Function Update_IndDlq_Goal()
Dim varRST As String
Set rsTbl = Nothing
If Forms("frm-AgentADD")![cmbDate] = "January" Then
varRST = "rsTbl.Fields(3)"
ElseIf Forms("frm-AgentADD")![cmbDate] = "February" Then
varRST = "rsTbl![02-yyyy]"
ElseIf Forms("frm-AgentADD")![cmbDate] = "March" Then
varRST = rsTbl.Fields(5)
End If
Set rsTbl = CurrentDb.OpenRecordset("DlqGoal(Ind)")
rsTbl.AddNew
rsTbl![Dept/Bucket] = Forms("frm-AgentADD")![txtDept].Value
rsTbl![AgentName] = Forms("frm-AgentADD")![txtAgentName].Value
rsTbl![AgentID] = Forms("frm-AgentADD")![txtAgentID].Value
varRST = Forms("frm-AgentADD")![Text27].Value
rsTbl.update
Set rsTbl = CurrentDb.OpenRecordset("tbl-Agents")
End Function
all code works except for what is colored RED. What I am wanting to do is, depending on the month selected, I want to add a value to that specific field.
The DlqGoal(Ind) table adds the name, dept, and id but no value for field(x)!
My table is set up as
F1= dept/bucket
F2= name
F3=id
F4=01-yyyy
F5=02-yyyy
F6=03-yyyy
so if the user selcts "February" then I want the value to populate in rsTbl![02-yyyy].
Any guesses, suggestions, answers maybe
Thanks