Hi,
I have been struggling to get this to work. So hopefully someone can guide me or help me out with this
I have a table called tblSupplierAddresses with 2 columns "SupplierName" and "Address"
I have a form which has a subform and both are called "frmMatRRSubform" and "frmDMRSubform"
In form "frmMatRRSubform" I have a field called "shipto" which I want to autopopulate when the form is open using the name of the supplier (Supplier) in the subform called "frmDMRSubform"
So the logic works as follows when the form opens up by the user the VBA code will take the value of the field "Supplier" in the "frmDMRSubform" and go into the "tblSupplierAddresses" matching "Supplier" in "frmDMRSubform" with "SupplierName" in "tblSupplierAddresses" once the match is found the VBA returns the value in "Address" in tblSupplierAddresses" and paste it in the field "shipto" in "frmMatRRSubform"
I have created the below so far but it doesn't work. Can anyone look and tell me what is wrong or what am I missing
Thanks
RB
I have been struggling to get this to work. So hopefully someone can guide me or help me out with this
I have a table called tblSupplierAddresses with 2 columns "SupplierName" and "Address"
I have a form which has a subform and both are called "frmMatRRSubform" and "frmDMRSubform"
In form "frmMatRRSubform" I have a field called "shipto" which I want to autopopulate when the form is open using the name of the supplier (Supplier) in the subform called "frmDMRSubform"
So the logic works as follows when the form opens up by the user the VBA code will take the value of the field "Supplier" in the "frmDMRSubform" and go into the "tblSupplierAddresses" matching "Supplier" in "frmDMRSubform" with "SupplierName" in "tblSupplierAddresses" once the match is found the VBA returns the value in "Address" in tblSupplierAddresses" and paste it in the field "shipto" in "frmMatRRSubform"
I have created the below so far but it doesn't work. Can anyone look and tell me what is wrong or what am I missing
Code:
Private Sub Form_Current()
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim strSupplier As String
If IsNull(Me.shipto) Then
Set db = CurrentDb
Set rs = db.OpenRecordset("tblSupplierAddresses", dbOpenDynaset)
strSupplier = DLookup("SupplierName", "tblSupplierAddresses", "[SupplierName]=" & Forms![frmMatRRSubform]![frmDMRSubform].Form.Supplier)
Me.shipto.Value = rs!Address
Set db = Nothing
Set rs = Nothing
End If
End Sub
RB