Noob question: executing select statement in VBA

Freak81

Registered User.
Local time
Today, 14:18
Joined
Nov 30, 2005
Messages
14
Hi,

I have a problem just executing a select statement. I want the value of a textbox to be determined by a simple select query.

I tried to use the Expression Builder but I don't know how to put arguments when using queries in it. For example, you want to select a field 'algemeenid' based on another field 'woningid'. If a query for this, named "selectionquery". Can anybody tell me how to do this?

Secondly, I tried to implement it as a visual basic function. I tried the following code, but it gives an error, and I don't know how to correct it.

This is the code
Code:
Private Sub Text25_Click()

Dim sql String
Dim rec As Recordset

sql = "SELECT algemeenid FROM woning WHERE woningid = 2;"
rec = DoCmd.OpenQuery(sql)

Text25 = rec

The error I get is a compile error "Expected Function or Variable". Could anyone please help? Any help on the syntax would be great.
 
rec = dlookup("algemeenid","woning","Winingid=2")
Christoph
 
Thanks for the help on this function Christophe. But, with this code

Code:
Private Sub Text25_Click()
Dim rec As Recordset

rec = DLookup("algemeenid", "WONING", "woningid=2")
End Sub

I get the compile error "Invalid use of property". Do you know how to correct it?

Thanks.

Freek
 
OK, lookup will give you a String

Dim strRetValue as String

will work
Christoph
 
or even
Text25 = DLookup("algemeenid", "WONING", "woningid=2")

Though you could really do with comming up with informative names for you fields :)

Peter
 
Lol.

I know, it's just for testing purposes :-)

Freak
 

Users who are viewing this thread

Back
Top Bottom