Ok. Thus far, I have two combo boxes. One with Rank, LastName, and FirstName concatenated together (and bound to CustomerPK). The other with Organization, ShopName, and OfficeSymbol concatenated together (and bound to Customer.PK). I have not yet worked on tblFacilityMgr, I'm focusing on tblRoomPOC right now.
Here is my code:
Code:
Option Compare Database
Private Sub cmdReset_Click()
Me.cboShop = ""
Me.cboFullName = ""
Call Form_Load
End Sub
Private Sub cmdAddRecord_Click()
If Not IsNull(Me.cboShop.Value) Or Not (Me.cboShop.Value) = "" Then
If MsgBox("Are you sure you would like to assign that customer to that room?", vbYesNo) = vbYes Then
Call AddShopEntry
Else
Call cmdReset_Click
End If
ElseIf Not IsNull(Me.cboFullName.Value) Or Not (Me.cboFullName.Value) = "" Then
If MsgBox("Are you sure you would like to assign that customer to that room?", vbYesNo) = vbYes Then
Call AddNameEntry
Else
Call cmdReset_Click
End If
End If
End Sub
Private Sub Form_Load()
Me.cboBuildingName.Visible = False
Me.cboRoomName.Visible = False
End Sub
Private Sub optCustIs_AfterUpdate()
If Me.optCustIs = 1 Then
Me.cboBuildingName.Visible = True
Me.cboRoomName.Visible = False
Else
Me.cboBuildingName.Visible = True
Me.cboRoomName.Visible = True
End If
End Sub
Private Sub AddShopEntry()
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
End Sub
Private Sub AddNameEntry()
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 this room." & vbCrLf & vbCrLf 'Change to Yes/No
Else
Rs.AddNew
Rs("CustomerFK").Value = Me.cboFullName
Rs("RoomFK").Value = Me.cboRoomName
Rs.Update
End If
End Sub
Essentially, what I'm trying to do is call AddShopEntry if the shop combo box is not null, or call AddNameEntry if the FullName combo box is not null. I feel like I have more code than I need and am probably over complicating it. But it works, for the most part.
My biggest problem is that I am not sure how to not allow both combo boxes to not be null at the same time. If cboShop is not null and its value is bound to one CustomerPK, but cboFullName is also not null and its value is bound to a different CustomerPK, that'd get confusing.
It would be nice if there was a way that both combo boxes could not be null and it'd work. Like, that the user could select a shop and also select a name and it'd give an error message if the two did not correspond.