MS Access VBA Value typed in txtbox1 should show values in txtbox2 and txtbox3

0

In MS Access 2016, the tbl01 has three fields: std_Id, stdnomb and std_nota. I have a form based on tbl01 and it has txtid, txtname and txtnota. I have been trying to write a code for the following: Al is To write a value in the txtid, the code must show the associated values in the txtname and the txtnota (see attached image).

In a preliminary way, I've tried this code, but, it does not work:

    Option Compare Database
Option Explicit
Sub txtid_AfterUpdate()
    Me.txtid.Value = Me.txtnombre
    Me.txtid.Value = Me.txtnota
End Sub

Welcome suggestions

    
asked by sabas 12.11.2018 в 16:55
source

1 answer

0

For this, you can use DLookUp.

Try this way:

Sub txtid_AfterUpdate()
    Me.txtnombre.Value = DLookUp("[stdnomb]","tbl01","[std_Id]=" & Me.txtid.Value
    Me.txtnota.Value = DLookUp("[std_nota]","tbl01","[std_Id]=" & Me.txtid.Value
End Sub

But if the 3 fields are in the same table, I think it would be much easier to simply create a form based on the tbl01 table and insert the fields you want to see. This would appear all the information already related, without using VBA code.

    
answered by 13.11.2018 / 02:36
source