Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 2nd, 2004, 10:26 AM
Authorized User
 
Join Date: Feb 2004
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

 
Old July 2nd, 2004, 11:24 AM
Authorized User
 
Join Date: Nov 2003
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
 
Old July 2nd, 2004, 11:47 AM
Authorized User
 
Join Date: Feb 2004
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

 
Old July 2nd, 2004, 12:15 PM
Authorized User
 
Join Date: Nov 2003
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
 
Old July 3rd, 2004, 04:41 AM
Authorized User
 
Join Date: Jul 2003
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





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





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