SQL inquiry

junyor

Registered User.
Local time
Today, 08:22
Joined
May 28, 2008
Messages
18
People,

I have a table called "User" and I need to get the "Perfil" field when customer informs the number "numero" field

Table - user:

numero - perfil
1 junior
2 master
3 pleno

something like that:
There is a text box (txtnumero) and a button (cmdbusca) on the form,
Once the number is entered and the button cmdbusca is clicked, I need to get the perfil field accordingly.

Does anyone know how to do this?
 
Welcome to the site. The simplest way would be to use a combo box instead of the textbox. The row source of the combo would be a query that returned both fields from that table. Then to get the second field you'd refer to the second column:

Forms!FormName.ComboName.Column(1)
 
Hi pbaldy!!!

But the problem is that the table has about 60000 records and it might be increased.

Is there any way to use a sql code to search the data from a table?

like:

"Select perfil from user where numero=txtnumero"

Tks.
 
Sorry for my ignorance but it didn't work... a message appeared:
Complile error: Expected: =

The code is as follows:

Private Sub cmd_Click()
DLookup("perfil", "user", "numero = " & Me.txtnumero)
End Sub

I was trying to do something like below but it didn't work too...

Private Sub cmd_Click()
Dim varPesquisarEst As Recordset
Set varPesquisarEst = DBEngine(0)(0).OpenRecordset("Select * FROM user WHERE numero =" & Me.txtnumero)
If varPesquisarEst.RecordCount > 0 Then
.....
Else
MsgBox "Estabelecimento não encontrado", _
vbInformation, "Atenção!"
End If
End Sub

Do you have a suggestion?

Tks.
 
Well, you can't just have the DLookup by itself like that. What are you trying to accomplish? Following your second logic:

Code:
If Not IsNull(DLookup("perfil", "user", "numero = " & Me.txtnumero)) Then
  ...
Else
  MsgBox "Estabelecimento não encontrado", _
    vbInformation, "Atenção!"
End If
 
Hi Pbaldy!

I'd like to thank you, it's working now!

Tks a lot
 
No problem;glad to hear it's working for you.
 

Users who are viewing this thread

Back
Top Bottom