Hi,
I have 2 Tables. Table "BOL" and Table "Containers". Both contain "Job_Number" and "Bill_of_Lading_Number" as a field. I would like to get a "Bill_of_Lading_Number" record from "BOL" and add it to "Bill_of_Lading_Number" in "Containers" table based on condition when both "Job_Number" are equal.
I have tried two methods. One with DLookup and another with SELECT. Both work but with a small problem.
When I execute them, a dialogue box popup asking me to enter the "Bill_of_Lading_Number" value while the required value shows as dialogue box heading. This box shouldn't come up and I am not sure why this is happening.
P.S. "varsJobCont" variable I get from another form and is "Job_Number" value that determines the record to be selected.
My Both Codes are:
=========================
Dim strBill As String
strBill = DLookup("Bill_of_Lading_Number", "BOL", "Job_Number = " & Application.TempVars("varsJobCont").Value)
DoCmd.RunSQL "Update Containers SET Bill_of_Lading_Number = " & strBill & " WHERE Job_Number = " & Application.TempVars("varsJobCont").Value
==========================
Dim strBill As String
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT BOL.Bill_of_Lading_Number FROM BOL WHERE BOL.Job_Number = " & Application.TempVars("varsJobCont").Value)
hello = rst.Fields(0).Value
DoCmd.RunSQL "Update Containers SET Bill_of_Lading_Number = " & strBill & " WHERE Job_Number = " & Application.TempVars("varsJobCont").Value
rst.Close
Set rst = Nothing
Set dbs = Nothing
======================================
Attached image below shows the dialogue box and the heading "bbb1055" is actually the correct value I needed to get. It should have been put in the other table automatically without the need to insert it manually again.
Any idea why this happening.
Thanks.
![]()