AccessAllAreas
Member
- Local time
- Today, 12:01
- Joined
- Jul 20, 2020
- Messages
- 42
Dear Experts
For me, this is big issue No.3 stopping me from completing this DB.
The Goal: On a bound form, with many different controls, one of which being a combo box control with a list of Managers/Team Leaders, and another being a check box indicating whether the person whose record it is is indeed a Manager/Team Leader or not. The goal is to be able to check the checkbox if they are a Manager/Team Leader, which would then update a separate table that contains all the list of the Managers/Team Leaders, adding the person's name into that record, then refreshing the combo box to show that new name as the Manager/Team Leader of themselves. And then, in reverse, if the check box is unchecked, we want to delete the record from the Manager/Team Leader table, update the combo box and then set it to blank (no selection made.)
The Form:
Bound to table: Tab_Emergency_Contact_List
Relevant Controls:
Publisher Surname (Text box)
Publisher First Name (Text box)
Group Overseer? (check box)
Group Overseer (combo box) - Data type - Number (Long integer), lookup source: SELECT [Tab_Group_Overseers].[GroupID], [Tab_Group_Overseers].[GODisplayName] FROM Tab_Group_Overseers ORDER BY [GODisplayName], [GroupID];
Here is my current code. Note: Again, I took more than one idea for doing this off of the Web and tried to convert it/ them to my needs. Hence, I am afraid it might be a mess. Sorry.
I know it is now a mess. Been working on this for months on and off.
Any assistance to get a workable solution will be greatly appreciated.
For me, this is big issue No.3 stopping me from completing this DB.
The Goal: On a bound form, with many different controls, one of which being a combo box control with a list of Managers/Team Leaders, and another being a check box indicating whether the person whose record it is is indeed a Manager/Team Leader or not. The goal is to be able to check the checkbox if they are a Manager/Team Leader, which would then update a separate table that contains all the list of the Managers/Team Leaders, adding the person's name into that record, then refreshing the combo box to show that new name as the Manager/Team Leader of themselves. And then, in reverse, if the check box is unchecked, we want to delete the record from the Manager/Team Leader table, update the combo box and then set it to blank (no selection made.)
The Form:
Bound to table: Tab_Emergency_Contact_List
Relevant Controls:
Publisher Surname (Text box)
Publisher First Name (Text box)
Group Overseer? (check box)
Group Overseer (combo box) - Data type - Number (Long integer), lookup source: SELECT [Tab_Group_Overseers].[GroupID], [Tab_Group_Overseers].[GODisplayName] FROM Tab_Group_Overseers ORDER BY [GODisplayName], [GroupID];
Here is my current code. Note: Again, I took more than one idea for doing this off of the Web and tried to convert it/ them to my needs. Hence, I am afraid it might be a mess. Sorry.
Code:
Public Sub cmbGroupOverseer_NotinList(NewData As String, Response As Integer)
Dim strSQL As String
Dim i As Integer
Dim Msg As String
Dim db As dao.Database
Dim rs As dao.Recordset
Set db = CurrentDb
Set rs = CurrentDb.OpenRecordset("Tab_Group_Overseers")
' DoCmd.OpenTable "Tab_Group_Overseers"
'Exit this sub if the combo box is cleared
' If NewData = "" Then
' Exit Sub
' End If
' NewData = (Me.Publisher_Surname = [Tab_Group_Overseers.GroupOverseerLastName]) & (Me.Publisher_First_Name = [Tab_Group_Overseers.GroupOverseerFirstName])
' NewData = (Me.Publisher_Surname.Value = (Tab_Group_Overseers.GroupOverseerLastName)) & (Me.Publisher_First_Name.Value = (Tab_Group_Overseers.GroupOverseerFirstName))
Msg = "'" & NewData & "' is not currently in the list of Group Overseers." & vbCr & vbCr _
& "Do you want to add it to the list?"
' i = MsgBox(Msg, vbQuestion + vbYesNo, "Unknown Group Overseer")
If MsgBox(Msg, vbQuestion + vbYesNo, "Unknown Group Overseer?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("Tab_Group_Overseers", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!Tab_Group_Overseers = NewData
rs.Update
If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
' If i = vbYes Then
' strSQL = "Insert Into Tab_Group_Overseers ([GroupOverseerLastName]) " & _
"values ('" & NewData & "');"
' CurrentDb.Execute strSQL, dbFailOnError
' Response = acDataErrAdded
' Else: Response = acDataErrContinue
' End If
' DoCmd.Close , [Tab_Group_Overseers]
' If MsgBox("Do you want to add " & " & NewData & " & " as a Group Overseer?", vbQuestion + vbYesNo) = vbNo Then
' Response = acDataErrContinue
' Me.Group_Overseer = Null
' Else
' CurrentDb.Execute "INSERT INTO Tab_Group_Overseers (GroupOverseerLastName) select " & " & NewData & "
' Response = acDataErrAdded
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
Private Sub Group_Overseer_Check_Box_Click()
Dim Response As Integer
Dim NewData As String
Call cmbGroupOverseer_NotinList(NewData, Response)
End Sub
I know it is now a mess. Been working on this for months on and off.
Any assistance to get a workable solution will be greatly appreciated.