Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query from access 1

Status
Not open for further replies.

falled

Programmer
Nov 3, 2006
47
ES
How can I exxecute a Query in access

I've got to relationed tables, and on a form I've got a comboBox with values of one field of a table.

I've got a label too.

I want to implement combobox_change, when it changes, put on the label the value of the other table which is relationed.

I hope you have understood me

B happy!
 
You may consider the DLookUp function.
Another common way is to already have the info in the combo and use the Column property.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Code:
Private Sub CodiPlanol_Change()
   Dim varX As Variant
   Dim varY As Variant
   varY = CodiPlanol.Value
   MsgBox (varY)
    varX = DLookup("[Description]", "Planol", "[Id] =" & varY)
    MsgBox (varX)
End Sub

What I'm doing wrong???????

Divided by 0!
 
What is the SQL code of CodiPlanol.RowSource ?
What is the value of varY ?
Which line of code raises the error ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Sorry

Table Planol(Id, Client, Description)

Codiplanol is ComboBox, with the Id.

I want that when CodiPlanol changes Show on a label the Description.

varY is the current value on the combobox, the msgBox are only to see if I'm catching the information I want.

Here is the error:
Code:
varX = DLookup("[Description]", "Planol", "[Id] =" & varY)


 
I asked what is displayed in the msgbox ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I asked about the VALUE physically displayed in the box.
 
Ok is Text, 50 chars long

sorry, I hope you refer to this
 
So, you may try this:
Code:
varX = DLookup("Description", "Planol", "Id='" & Replace(varY, "'", "''") & "'")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Your are a genius!!!!!!

What was wrong?? why replace function!?
 
What was wrong
Id is defined as text in Planol, so you need to surrond the literal value with single quotes.

why replace function
To quote any single quotes in the value of varY

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top