Re: using the results of a SQL SELECT(COUNT) statement in VBA
From: Dan Artuso (dartuso_at_NSpagepearls.com)
Date: 09/23/04
- Next message: Douglas J. Steele: "Re: Prefill NT Log on ID into field on a form"
- Previous message: Stephen Lebans: "Re: RichText in a "classic" TextBox"
- In reply to: Paul James: "using the results of a SQL SELECT(COUNT) statement in VBA"
- Next in thread: Paul James: "Re: using the results of a SQL SELECT(COUNT) statement in VBA"
- Reply: Paul James: "Re: using the results of a SQL SELECT(COUNT) statement in VBA"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 22 Sep 2004 20:08:34 -0400
Hi,
You would have to open a recordset against the statement and then assign
the value to a variable OR you can use DCount
vMatchedCount = DCount("[ReceiptId]","tblReceipt","Matched = 0"
-- HTH Dan Artuso, Access MVP "Paul James" <pponzelliBEGONE@SPAMsurewest.FOREVERnet> wrote in message news:10l42lmgcjo3vd7@corp.supernews.com... > I'd like to run a SQL statement which will return a single number, and > assign this number to a variable. > > Here's the SQL statement: > > "SELECT COUNT(ReceiptID) from tblReceipt WHERE Matched=0" > > How do I tell VBA that I want to assign the single-number result of that > SELECT statement to the variable vMatchedCount? > > I've tried: > > vMatchedCount = "SELECT COUNT(ReceiptID) from tblReceipt WHERE Matched=0" > > but that just assigns the entire statement as a text string to the variable. > > I tried the same thing without the quotation marks, but that produces the > error "Expected: expression." > > There's nothing wrong with the SQL statement itself. I tested it as a query > in the database window and it works fine. I just can't figure out how to > get it to assign the result to a variable in VBA. Could someone please tell > me how do do this? > > Thanks in advance, > > Paul > >
- Next message: Douglas J. Steele: "Re: Prefill NT Log on ID into field on a form"
- Previous message: Stephen Lebans: "Re: RichText in a "classic" TextBox"
- In reply to: Paul James: "using the results of a SQL SELECT(COUNT) statement in VBA"
- Next in thread: Paul James: "Re: using the results of a SQL SELECT(COUNT) statement in VBA"
- Reply: Paul James: "Re: using the results of a SQL SELECT(COUNT) statement in VBA"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|