Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 2nd, 2004, 10:26 AM
Authorized User
 
Join Date: Feb 2004
Location: , , Canada.
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to chacquard
Default SQL record count / recordset

Hi,

I need help with this problem. I have some code that has to run if I have records that have specific criterias. I don't need to get the list of records, just need to know if the record count is 0 or not.

Here is the code I have.


    Dim rec As Recordset
    Dim db As Database
    Dim strSQL As String

strSQL = "SELECT COMMANDES.RefCommande " & _
"FROM ((COMMANDES INNER JOIN COMMANDESDetails ON COMMANDES.IdCommande = COMMANDESDetails.IdCommande) INNER JOIN MASTERSHOW ON COMMANDESDetails.IdMaster = MASTERSHOW.IdMaster) INNER JOIN RESUME ON MASTERSHOW.IdEvenement = RESUME.IdResume " & _
"WHERE RESUME.CodeEvenement)= " & [parmResume] & "AND " & "COMMANDES.StatutDepenses= 0 ;"

        Set db = CurrentDb()
        Set rec = db.OpenRecordset(strSQL, dbOpenDynaset)

        If rec.RecordCount > 0 Then ...

        Else ...

When I run this code, I get a message stating "not enough parameters... 1 expected". When I step through my code, I get this message at the "set rec = db.openrecordset..."

Can anyone help me with this please ... :(

Chantal

Reply With Quote
  #2 (permalink)  
Old July 2nd, 2004, 11:24 AM
Authorized User
 
Join Date: Nov 2003
Location: Commerce Twp, MI, USA.
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

While you have the VBE open in debug mode, open the Immediate window and enter ?strSQL to show the SQL string. My guess is that your literal [parmResume] is a variable parameter for the query and you haven't assigned a value to it.


Darrell L. Embrey
Reply With Quote
  #3 (permalink)  
Old July 2nd, 2004, 11:47 AM
Authorized User
 
Join Date: Feb 2004
Location: , , Canada.
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to chacquard
Default

You are right... My problem is with the parmResume... but I do assign it a value through a form. I just don't know how to do the statement for SQL to use the value of my variable. Can you help me ?


Thanks.

Chantal

Reply With Quote
  #4 (permalink)  
Old July 2nd, 2004, 12:15 PM
Authorized User
 
Join Date: Nov 2003
Location: Commerce Twp, MI, USA.
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Use the name of the control (i.e. textbox, combobox, listbox) on the form that holds the value for your variable. For example, if the control's name is txtResume, replace [parmResume] with Me.txtResume. Your new SQL string would be as follows:
strSQL = "SELECT COMMANDES.RefCommande " & _
"FROM ((COMMANDES INNER JOIN COMMANDESDetails ON COMMANDES.IdCommande = COMMANDESDetails.IdCommande) INNER JOIN MASTERSHOW ON COMMANDESDetails.IdMaster = MASTERSHOW.IdMaster) INNER JOIN RESUME ON MASTERSHOW.IdEvenement = RESUME.IdResume " & _
"WHERE RESUME.CodeEvenement)= " & Me.txtResume & "AND " & "COMMANDES.StatutDepenses= 0 ;"


Darrell L. Embrey
Reply With Quote
  #5 (permalink)  
Old July 3rd, 2004, 04:41 AM
Authorized User
 
Join Date: Jul 2003
Location: Stockton on Tees, , United Kingdom.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If Me.txtResume is text then this bit of coding need to include '

....."WHERE RESUME.CodeEvenement)= " & Me.txtResume & "AND " & "COMMANDES.StatutDepenses= 0 ;"

i.e.

....."WHERE RESUME.CodeEvenement)= '" & Me.txtResume & "' AND COMMANDES.StatutDepenses= 0 ;"


Cheers Ray

Cheers Ray
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count string occurences across recordset goldstein SQL Server 2005 1 July 9th, 2007 06:47 PM
Recordset Count starting from 1 till end nouky Classic ASP Databases 24 October 30th, 2006 06:22 PM
Recordset count niravp Classic ASP Databases 6 October 26th, 2003 02:41 PM
How to count a record when it is not there Mitch Access 1 October 3rd, 2003 03:49 PM



All times are GMT -4. The time now is 06:02 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.