Results 1 to 5 of 5

Thread: sql statement

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    Cleveland,Oh
    Posts
    95

    sql statement

    Hi:
    Can someone please tell me what is I am doing wrong with this statement. The statement is returning 0 and I know there are at least 100 records in my table.


    I think the problem is with the date. I am not be converting the date to its proper datatype.

    lcsql = "Select * from TaxName Where Meeting_ID= " & _
    Chr(39) & Trim(Str(iMeeting_ID)) & Chr(39) & _
    " And Event_Date =" & "02/02/2004"


    oRecData.Open lcsql, oDataConn
    x= oRecData.RecordCount
    Zus

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Probably because you are not specifing the cursor type and lock
    type. The default cursor type is FowardOnly when it is not
    specified. This will make the RecordCount property reflect a -1
    because the RecordCount property is not supported with a
    FowardOnly cursor type. Change to Keyset or Static.
    To test for records with any type of cursor, use this...
    VB Code:
    1. oRecData.Open lcsql, oDataConn, adOpenKeyset, adLockOptimistic, adCmdText
    2. If oRecData.BOF = False and oRecData.EOF = False Then
    3.     'Do record manipulation or ???
    4. Else
    5.     MsgBox "No Records Returned!", vbOkOnly+vbInformation, App.ProductName
    6. End If
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    Cleveland,Oh
    Posts
    95

    sql statement

    The statement below does return records if I do not include date. For example:

    lcsql = "Select * from TaxName Where Meeting_ID= " & _
    Chr(39) & Trim(Str(iMeeting_ID)) & Chr(39)

    The problem is when I include the date. Why does it not like the date?


    lcsql = "Select * from TaxName Where Meeting_ID= " & _
    Chr(39) & Trim(Str(iMeeting_ID)) & Chr(39) & _
    " And Event_Date =" & "02/02/2004"

    Thanks
    Zus

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    Cleveland,Oh
    Posts
    95

    resolved:sql statement

    Thanks all:
    I figured out what was the issue. I needed to add extra digit if the month value 2 needed to be (02).

    Thanks again
    Zus

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    What is the field definition for Event_Date?
    If it is text then enclose the date with apostrophies. If it is
    formatted as a Date/Time filed, then try adding the pound
    character around your date value.
    VB Code:
    1. lcsql = "Select * from TaxName Where Meeting_ID= " & _
    2. Chr(39) & Trim(Str(iMeeting_ID)) & Chr(39) & _
    3. " And Event_Date ='02/02/2004'"
    4.  
    5. 'OR
    6.  
    7. lcsql = "Select * from TaxName Where Meeting_ID= " & _
    8. Chr(39) & Trim(Str(iMeeting_ID)) & Chr(39) & _
    9. " And Event_Date =#02/02/2004#"
    10.  
    11. oRecData.Open lcsql, oDataConn, adOpenKeyset, adLockOptimistic, adCmdText
    12. If oRecData.BOF = False and oRecData.EOF = False Then
    13.     'Do record manipulation or ???
    14. Else
    15.     MsgBox "No Records Returned!", vbOkOnly+vbInformation, App.ProductName
    16. End If
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width