01-29-2020 01:07 PM
01-29-2020 01:07 PM
I have a question in relation to a infopath. So I'm trying to figure out how to auto populate fields based on conditions. So I have purchase order form that I'm creating where certain fields will auto populate based on what I select from a drop down box. The main condition is the supplier I choose, and what will auto populate will be the supplier's address, country, phone number, fax, the main contact, and so on.
I attached the form for reference. I've been trying to create a rule that links to the supplier name field, where the condition is if that field contains a supplier name then "run these actions" which will display the correct address for that particular supplier. So I believe the rule type should be "Action", which then prompts the rule detail, which should be the field: which is the SupplierName field, and the value which would be the supplier's address. Although this is not displaying in the preview mode when I select the certain supplier from the drop down box.
I attached a picture showing what I'm trying to do. Again the contain is SupplierName (in this particular situation) contains: Oehderstrasse 28 D-42289 Wuppertal, GER 42289
and the rule type is action where if this is satisfied then it will display the supplier's address.
Can let me know if I'm doing this correct, if not please tell me know to execute this properly.
02-13-2020 09:40 AM
I think you need to connect code to the after_update event.
You could run for every field you need
me.FldAdress.text = dlookup("Adress" ,"TblSuppliers" ,"ID=" &me. cmboOfSupplier.value
me.FldPlace.text = dlookup("Place" ,"TblSuppliers" ,"ID=" &me. cmboOfSupplier.value
I think this is most easy to understand but creates for every field a run on the database.
Other option is to extend the combo where you select the supplier with more columns and make them invisible with 0cm width and point to them with VBA with the after_update event.
Third option is to open a recordset with VBA and collect the needed fields.
Dim dbs As DAO.Database
Dim rsSQL As DAO.Recordset
Dim strSQL As String
Set dbs = CurrentDb
strSQL = "SELECT * FROM tblSuppliers WHERE ID =" & me.cmboSupplier.value
Set rsSQL = dbs.OpenRecordset(strSQL, dbOpenSnapshot)
if rsSQL.recordcount > 0 then
me.fldAdress.text = rsSQL!Adress
me.fldPlace.text = rsSQL!Place
' and so on
Set rsSQL = nothing