Using Returned vba SQL Results

  • Thread starter Thread starter sherriross81
  • Start date Start date
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.
 
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.
 
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.
 
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.
 
Back
Top