Solved Use select to define the value of a var (1 Viewer)

Versus

New member
Local time
Today, 00:38
Joined
May 24, 2020
Messages
5
Hello, I'm trying to use "Select" to define the value of a Var

My try:

Code:
CodigoRequisicaoDevolucao = "SELECT * FROM tabela_ferramentas WHERE PatrimonioFerramenta = '" & Me.txt_inserir_patrimonio & "'"

But when i use MsgBox to check the value of the var this is the result:

example.png


There is a way to make this work ?
 

Cronk

Registered User.
Local time
Today, 13:38
Joined
Jul 4, 2013
Messages
2,772
Your variable as you have found will only contain the SQL string. You need to open a recordset to get the values of the fields in the record(s) selected
Code:
dim CodigoRequisicaoDevolucao as recordset

set CodigoRequisicaoDevolucao = db.openrecordset()"SELECT * FROM tabela_ferramentas WHERE PatrimonioFerramenta = '" & Me.txt_inserir_patrimonio & "'")
You can then get the value from rst(n) where n is the number of the field in the table, or alternatively rst!YourFieldName where YourFieldName is the name of the field.

To get a single value, most would use Dlookup
Code:
msgbox Dlookup ("YourFieldName", "tabela_ferramentas", "PatrimonioFerramenta = '" & Me.txt_inserir_patrimonio & "'")
 

Users who are viewing this thread

Top Bottom