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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OpenRecordset 2

Status
Not open for further replies.

beckyh

Programmer
Apr 27, 2001
126
US
How do I return the result of this SQL statement. I want to pass the value to a module.

sql = "SELECT COUNT(QuoteItemNumber) AS CountOfQuoteItemNumber FROM QuoteHeader GROUP BY QuoteNumber HAVING (QuoteNumber = 'q-021305-799')"

Set rs = db.OpenRecordset(sql)
 
The value is rs(0)

You may also consider the DCount function:
DCount("*", "QuoteHeader", "QuoteNumber='q-021305-799'")


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
The value of the SQL statement is 7. I want to pass that value. Not 0. Is there a way to pass 7?
 
Nevermind. The Dcount worked like a charm!
 
Code:
Set rs = db.OpenRecordset(sql)

With rs
   intWhatever = .Fields("CountOfQuoteItemNumber")
End With

Is that what you mean? Actually, a shorter way of doing that is:

Code:
intWhatever CurrentDb.OpenRecordset(sql).Fields("CountOfQuoteItemNumber")
 
Crap, I mean
Code:
intWhatever = CurrentDb.OpenRecordset(sql).Fields("CountOfQuoteItemNumber")
Sorry, forgot the =.
 
PHV,
When I changed it to

count = DCount("*", "QuoteHeader", "QuoteNumber='[Forms]![Issue Quote Form]![QuoteNumber]'")

it doesn't work any longer. Can't I call the number from the Issue Quote Form??

I get an error saying "This property is read-only and can't be set.
 
myCount = DCount("*", "QuoteHeader", "QuoteNumber='[Forms]![Issue Quote Form]![QuoteNumber]'")

Count is a reserved word.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Sometimes you'll need to concatenate the value into the criterion, not the reference:

[tt]myCount = DCount("*", "QuoteHeader", "QuoteNumber='" & [Forms]![Issue Quote Form]![QuoteNumber] & "'")[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top