I have a bit of a headscratcher here. Perhaps I am going about this in the wrong way - if anyone has methodology they think would work better please don't hesitate to call me a dummy! As for background in what I am actually trying to accomplish:
Firstly, I have a single form and 2 tables I am working with and they are: Tbl_CustomerShipToLocation, Tbl_MasterCustomerList, and Frm_NewShipToLocation.
Tbl_CustomerShipToLocation
- Customer_ID - Number - PK
- Customer_Name - Short Text - PK - (lookup value from Tbl_MasterCustomerList; Customer_Name)
- Ship_To_Location - Short Text - PK
This is a triple PK because of complex customer information. We have multiple companies that require different processes for the same part based on which location they are ordering for.
Tbl_MasterCustomerList
- Customer_ID - Number - PK
- Customer_Name - Short Text
- Contact Person / CP Email / CP Phone Number (These are not being used in my current Form struggles.)
Now for the Meat and Potatoes
I have a simple creation form for new Ship To Locations:
Simply saving the record always left Customer_Name blank because it is a lookup field linked to Customer_ID in Tbl_MasterCustomerList, but displaying the corresponding Customer_Name. Here is my code for the Save Form button:
Private Sub Save_Form_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim CustID As Long
Dim CustName As String
Set db = CurrentDb
Set rs = db.OpenRecordset("Tbl_CustomerShipToLocation")
'Open Tbl_CustomerShipToLocation as recordset
CustID = Me.cmbo_Customer_Name.Value
CustName = DLookup("[Customer_Name]", "Tbl_MasterCustomerList", "[Customer_ID] =" & CustID)
With rs
.AddNew 'Add new record with values from Frm_NewShipToLocation
![Customer_Name] = CustName
![Customer_ID] = Me.txt_Customer_ID.Value
![Ship_To_Location] = Me.txt_Ship_To_Location.Value
.Update
End With
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
And here is what VBA is pulling:
I understand why the value of by Customer_Name Combo is pulling in Numbers, I just don't understand how or why it always pulls an incorrect ID. If I use Customer_ID = 2072 for example VBA pulls in 70.
I don't even have entries with Customer_ID = 126 or Customer_ID = 70.
If you've stuck around this far, thank you! As always any suggestions are very much appreciated, but doubly so in this case - I am about this close || to losing my mind.