Solved Retrieve value and not primary key from Data Access Objects (DAO) (1 Viewer)

Ashisht76

Member
Local time
Today, 23:22
Joined
Jan 31, 2022
Messages
44
To begin with I am tankful for your precious time to watch this and thankful for help in advance.

Content1 is lookup field. This value coming from another table. In current table (i.e. TblQuality ) its showing value but in Debug.Print Stg its giving primary key. How can i retrieve value and not primary key. I have trim this code to simplest however i am truncating fields as per certain conditions with help of for next loop but for ease of my understanding i have removed that part.

Private Sub Command23_Click()

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim Stg As Variant
Dim fld As Field
Set db = CurrentDb
strSQL = "SELECT * FROM TblQuality WHERE QualityID = " & Me!QualityID
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)

Stg = rst!Content1
Debug.Print Stg

rst.Close
Set rst = Nothing
Set db = Nothing
End Sub

I highly appreciate your valuable support. Thanks to everyone for support.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 13:52
Joined
May 21, 2018
Messages
8,529
You should get rid of all table level lookup fields.
In tblquality you are storing a pk to some other table probably tblContent. Your SQL then needs to include a join pulling in Content description.
 

Ashisht76

Member
Local time
Today, 23:22
Joined
Jan 31, 2022
Messages
44
You should get rid of all table level lookup fields.
In tblquality you are storing a pk to some other table probably tblContent. Your SQL then needs to include a join pulling in Content description.
Thanks a lot. That was great help and educational one. I learnt is table level look up is NO NONO...
 

Users who are viewing this thread

Top Bottom