Using Returned vba SQL Results

S

sherriross81

Hello,

I have a query that returns a result. I want to use the result that it
returns and have it display in a text box on my form. Here is my code:

Dim strSQL As String
strSQL = "Select ID FROM [Computer Inventory] " _
& "WHERE [PC Name] = '" & Me.cboComputerName & "'"


Me.txtComputerIDCode = strSQL

When I assign it to strSQL it returns that entire select statement. How can
I return the ID that it selected?

Thanks in advance.
 
D

Dale Fye

You need to use the DLOOKUP command instead of the SQL. Try:

Dim strCriteria as string
strCriteria = "[PC Name] = '" & me.cboComputerName & "'"
me.txtComputerIDCode = DLOOKUP("ID", "Computer Inventory", strCriteria)

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 
S

sherriross81

That worked perfectly. I am so glad you showed me how to do that I will
definitely be using that in the future :).

Dale Fye said:
You need to use the DLOOKUP command instead of the SQL. Try:

Dim strCriteria as string
strCriteria = "[PC Name] = '" & me.cboComputerName & "'"
me.txtComputerIDCode = DLOOKUP("ID", "Computer Inventory", strCriteria)

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



sherriross81 said:
Hello,

I have a query that returns a result. I want to use the result that it
returns and have it display in a text box on my form. Here is my code:

Dim strSQL As String
strSQL = "Select ID FROM [Computer Inventory] " _
& "WHERE [PC Name] = '" & Me.cboComputerName & "'"


Me.txtComputerIDCode = strSQL

When I assign it to strSQL it returns that entire select statement. How can
I return the ID that it selected?

Thanks in advance.
 
D

Dale Fye

Sherri,

You don't really need the dim and strCriteria. You can put that all on one
line, but I prefer to break it up for readability.

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



sherriross81 said:
That worked perfectly. I am so glad you showed me how to do that I will
definitely be using that in the future :).

Dale Fye said:
You need to use the DLOOKUP command instead of the SQL. Try:

Dim strCriteria as string
strCriteria = "[PC Name] = '" & me.cboComputerName & "'"
me.txtComputerIDCode = DLOOKUP("ID", "Computer Inventory", strCriteria)

--
HTH
Dale

Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



sherriross81 said:
Hello,

I have a query that returns a result. I want to use the result that it
returns and have it display in a text box on my form. Here is my code:

Dim strSQL As String
strSQL = "Select ID FROM [Computer Inventory] " _
& "WHERE [PC Name] = '" & Me.cboComputerName & "'"


Me.txtComputerIDCode = strSQL

When I assign it to strSQL it returns that entire select statement. How can
I return the ID that it selected?

Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top