Thanks again for the help.
I've solved the problem of the null combo boxes. It was really easy. I simply set the other combo box's value to nothing in the AfterUpdate event.
I have a very long if statement to deal with if it is in one combo box, or the other. Also if they're a facility manager or a room POC. You were right about setting the focus to a save place. I keep getting errors, need to fix that. Also, I still haven't created a private sub for noCustomerReset, its on the list. I'm aware there's lots of areas like that I can reduce code, and I will.
Code:
Private Sub cmdReset_Click()
Me.cboShop = ""
Me.cboFullName = ""
Call Form_Load
End Sub
Private Sub cmdAddRecord_Click()
Dim isPerson As Boolean
Dim isRoomPOC As Boolean
isPerson = False
isPerson = isPerson Or Not Me.cboFullName.Value = "" And Not IsNull(Me.cboFullName.Value)
isRoomPOC = False
isRoomPOC = isRoomPOC Or Not Me.cboRoomName.Value = "" And Not IsNull(Me.cboRoomName.Value)
If isRoomPOC Then
If isPerson Then
If IsNull(Me.cboRoomName.Value) Or (Me.cboRoomName.Value) = "" Then
If MsgBox("Please ensure you've selected a Room name. Would you like to try again?", vbYesNo) = vbYes Then
Else
Call cmdReset_Click
End If
Else
If MsgBox("Are you sure you would like to assign that customer to that room?", vbYesNo) = vbYes Then
Call AddNamePOCEntry
Else
Call cmdReset_Click
End If
End If
Else
If IsNull(Me.cboRoomName.Value) Or (Me.cboRoomName.Value) = "" Then
If MsgBox("Please ensure you've selected a room name. Would you like to try again?", vbYesNo) = vbYes Then
Else
Call cmdReset_Click
End If
Else
If MsgBox("Are you sure you would like to assign that customer to that building?", vbYesNo) = vbYes Then
Call AddShopPOCEntry
Else
Call cmdReset_Click
End If
End If
End If
ElseIf isPerson Then
If IsNull(Me.cboBuildingName.Value) Or (Me.cboBuildingName.Value) = "" Then
If MsgBox("Please ensure you've selected a Building name. Would you like to try again?", vbYesNo) = vbYes Then
Else
Call cmdReset_Click
End If
Else
If MsgBox("Are you sure you would like to assign that customer to that room?", vbYesNo) = vbYes Then
Call AddNameFacilityEntry
Else
Call cmdReset_Click
End If
End If
Else
If IsNull(Me.cboBuildingName.Value) Or (Me.cboBuildingName.Value) = "" Then
If MsgBox("Please ensure you've selected a building name. Would you like to try again?", vbYesNo) = vbYes Then
Else
Call cmdReset_Click
End If
Else
If MsgBox("Are you sure you would like to assign that customer to that building?", vbYesNo) = vbYes Then
Call AddShopFacilityEntry
Else
Call cmdReset_Click
End If
End If
End If
End Sub
Private Sub Form_Load()
Me.cboBuildingName.Visible = False
Me.cboRoomName.Visible = False
Me.Box41.Visible = False
Me.Box44.Visible = False
Me.Label43.Visible = False
Me.Label45.Visible = False
Me.cmdAddRecord.Visible = False
Me.optCustIs.Value = 0
End Sub
Private Sub optCustIs_AfterUpdate()
If Me.optCustIs = 1 Then
Me.cboBuildingName.Visible = True
Me.cboRoomName = ""
Me.cboRoomName.Visible = False
Me.Box41.Visible = True
Me.Label43.Visible = True
Me.Label45.Visible = False
Me.Box44.Visible = False
Me.cmdAddRecord.Visible = True
Else
Me.cboBuildingName.Visible = True
Me.cboRoomName.Visible = True
Me.Box44.Visible = True
Me.Label45.Visible = True
Me.Box41.Visible = False
Me.cmdAddRecord.Visible = True
End If
End Sub
Private Sub cboShop_AfterUpdate()
If Not IsNull(Me.cboShop.Value) Or Not (Me.cboShop.Value) = "" Then
Me.cboFullName = ""
Me.lstFacilityMgr.RowSource = " SELECT tblFacilityMgr.CustomerFK, tblBuilding.BuildingName AS Building " _
& " FROM tblBuilding INNER JOIN tblFacilityMgr ON tblBuilding.BuildingPK = tblFacilityMgr.BuildingFK " _
& " WHERE (((tblFacilityMgr.CustomerFK)=[cboShop]))"
Me.lstRoomPOC.RowSource = " SELECT tblRoomPOC.CustomerFK, tblBuilding.BuildingName, tblRoom.RoomName " _
& " FROM (tblBuilding INNER JOIN tblRoom ON tblBuilding.BuildingPK = tblRoom.BuildingFK) INNER JOIN tblRoomPOC " _
& " ON tblRoom.RoomPK = tblRoomPOC.RoomFK " _
& " WHERE (((tblRoomPOC.CustomerFK) = [cboShop]))" _
& " ORDER BY tblBuilding.BuildingName, tblRoom.RoomName "
End If
Me.lstFacilityMgr.Requery
End Sub
Private Sub cboFullName_AfterUpdate()
If Not IsNull(Me.cboFullName.Value) Or Not (Me.cboFullName.Value) = "" Then
Me.cboShop = ""
Me.lstFacilityMgr.RowSource = " SELECT tblFacilityMgr.CustomerFK, tblBuilding.BuildingName AS Building " _
& " FROM tblBuilding INNER JOIN tblFacilityMgr ON tblBuilding.BuildingPK = tblFacilityMgr.BuildingFK " _
& " WHERE (((tblFacilityMgr.CustomerFK)=[cboFullName]));"
Me.lstRoomPOC.RowSource = " SELECT tblRoomPOC.CustomerFK, tblBuilding.BuildingName, tblRoom.RoomName " _
& " FROM (tblBuilding INNER JOIN tblRoom ON tblBuilding.BuildingPK = tblRoom.BuildingFK) INNER JOIN tblRoomPOC " _
& " ON tblRoom.RoomPK = tblRoomPOC.RoomFK " _
& " WHERE (((tblRoomPOC.CustomerFK) = [cboFullName])) " _
& " ORDER BY tblBuilding.BuildingName, tblRoom.RoomName "
End If
Me.lstFacilityMgr.Requery
End Sub
Private Sub AddShopFacilityEntry()
Set db = CurrentDb
Set Rs = db.OpenRecordset("tblFacilityMgr")
If DCount("*", "tblFacilityMgr", "[CustomerFK]=" & Me.cboShop & " And [BuildingFK] =" & Me.cboBuildingName & "") > 0 Then
MsgBox "That customer is already assigned as a Facility Manager for this building." & vbCrLf & vbCrLf 'Change to Yes/No
Else
Rs.AddNew
Rs("CustomerFK").Value = Me.cboShop
Rs("BuildingFK").Value = Me.cboBuildingName
Rs.Update
End If
Me.lstFacilityMgr.Requery
End Sub
Private Sub AddShopPOCEntry()
Set db = CurrentDb
Set Rs = db.OpenRecordset("tblRoomPOC")
If DCount("*", "tblRoomPOC", "[CustomerFK]=" & Me.cboShop & " And [RoomFK] =" & Me.cboRoomName & "") > 0 Then
MsgBox "That customer is already assigned as a point of contact for this room." & vbCrLf & vbCrLf 'Change to Yes/No
Else
Rs.AddNew
Rs("CustomerFK").Value = Me.cboShop
Rs("RoomFK").Value = Me.cboRoomName
Rs.Update
End If
Me.lstRoomPOC.Requery
End Sub
Private Sub AddNameFacilityEntry()
Set db = CurrentDb
Set Rs = db.OpenRecordset("tblFacilityMgr")
If DCount("*", "tblFacilityMgr", "[CustomerFK]=" & Me.cboFullName & " And [BuildingFK]=" & Me.cboBuildingName & "") > 0 Then
MsgBox "That customer is already assigned as a Facility manager for that building." & vbCrLf & vbCrLf 'Change to Yes/No
Else
Rs.AddNew
Rs("CustomerFK").Value = Me.cboFullName
Rs("BuildingFK").Value = Me.cboBuildingName
Rs.Update
End If
Me.lstFacilityMgr.Requery
End Sub
Private Sub AddNamePOCEntry()
Set db = CurrentDb
Set Rs = db.OpenRecordset("tblRoomPOC")
If DCount("*", "tblRoomPOC", "[CustomerFK]=" & Me.cboFullName & " And [RoomFK]=" & Me.cboRoomName & "") > 0 Then
MsgBox "That customer is already assigned as a Point of Contact for that room." & vbCrLf & vbCrLf 'Change to Yes/No
Else
Rs.AddNew
Rs("CustomerFK").Value = Me.cboFullName
Rs("RoomFK").Value = Me.cboRoomName
Rs.Update
End If
Me.lstRoomPOC.Requery
End Sub
Anyhow, I will do what you said w/ this query. I think you're right about the join between tblOrganization and tblCustomer, but I don't think thats going to resolve my problem. More I think about it, I'm going to run into problems when I get at work and put real data here because although every customer has an OrganizationName, not all customers have a ShopName, and not all Customers have an OfficeSymbol (its one, the other, or both).
Still doesn't resolve the bigger issue. I'm getting duplicate values because its bound to CustomerPK. I'm trying to use GROUP BY to remove them, but I'm definitely doing something wrong.