Results 1 to 9 of 9

Thread: This is "really" newbie stuff, but....

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Barrie, Ontario - Canada
    Posts
    85

    This is "really" newbie stuff, but....

    Hi Everybody,

    I need to scan a rather short mdb table ( It's a list of city names, about 20 records) to see if a city name exists in the table. The searchKey is contained in a combobox.Text property.

    Building an SQL request is whats making me crazy because of its string manipulation. (I think)
    Here's the code I have worked out so far, along with Visual Basic-6 complaint:

    Private Sub SeeCmbCity()
    ' Finds a record to match city name, or allows for a new record
    ' to be entered into the city table
    Dim rsData2 As ADODB.Recordset
    Dim cString As String
    cString = Trim(cmbCust(1))
    Set rsData2 = New ADODB.Recordset
    rsData2.Open "SELECT * FROM city where city=" & cString, cnDB,
    adOpenDynamic, adLockOptimistic
    '
    ' VB6 ends with a run-time error. something about too few parameters.
    '

    End Sub

    So I have two questions really...
    (1) What have I done wrong with the rsData2.Open statement?

    (2) Is it smart to place all data in a single file like mdb does. Clipper would have maintained seperatye databases.

    Thanks,
    -Paul-

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: This is "really" newbie stuff, but....

    I am not very good with SQL...but my ADO open looks like this

    VB Code:
    1. RsStorage.Open "Splits", cn, adOpenKeyset, adLockPessimistic, adCmdTable

    where Splits is the name of the table
    and cn is the active connection

    then to get the data i do

    VB Code:
    1. Do while NOT rsStorage.EOF
    2.      If rsStorage.Fields("City") = cstring Then
    3.           'Add whatever
    4.      End If
    5. rsStorage.MoveNext
    6. Loop

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: This is "really" newbie stuff, but....

    VB Code:
    1. Dim rsData2 As ADODB.Recordset
    2. Dim cString As String
    3. 'cString = Trim(cmbCust(1)) i am not sure what cmbCust(1) is.  Do you have
    4. 'an array of combo boxes called cmbCust?
    5. Set rsData2 = New ADODB.Recordset
    6. rsData2.Open "SELECT * FROM city where city= '" & cString & "'", cnDB,
    7. adOpenDynamic, adLockOptimistic

    One of the things that took a while for me to get used to was that databases like Access and SQL Server have just one database with multiple tables unlike Clipper or dBase that had multiple databases with one table. One database, multiple tables are much, much easier and more efficient to deal with.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: This is "really" newbie stuff, but....

    You should have this line of code all on one line and what is the search criteria? Does it have any illegal or issue causing characters?
    Also, if the search criteria is text then you should place single quotes around it.

    VB Code:
    1. rsData2.Open "SELECT * FROM city where city='" & cString & "';", cnDB, adOpenDynamic, adLockOptimistic, adCmdText
    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

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: This is "really" newbie stuff, but....

    Quote Originally Posted by RobDog888
    You should have this line of code all on one line
    Good point, and I also forgot to put in the ; in my example.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: This is "really" newbie stuff, but....

    Boooo, bad Hack, *SLAP* Jk

    The only other issue is the criteria containing delimiters like apostrophies, astericks, or percent signs. Apostrophies are probably the #1 cause
    of criteria issues. Can you post an example of what your passing?
    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

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Barrie, Ontario - Canada
    Posts
    85

    Re: This is "really" newbie stuff, but....

    Thanks RobDog888, Hack, and kfcSmitty.

    It was the quotation mark thing that was killing me. I'l keep working on understanding that stuff.... folks say that SQL is "the way to go" but I couldn't judge anyway.

    Thanks again for the solution and the help

    -Paul-

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: This is "really" newbie stuff, but....

    You can get around the single quote issue by checking for it and doubling up on it in order to get the SQL correct.
    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

  9. #9
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: This is "really" newbie stuff, but....

    Take a look at #7 Question in the Frequently Asked Questions link in my signature.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

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