Results 1 to 38 of 38

Thread: Can someone help me?

  1. #1

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Can someone help me?

    I need to use a database with my application I'm making.

    I have searched many websites and the all keep giving me something like this,

    VB Code:
    1. Dim TutVB4DB As Database
    2. Dim TutRS As Recordset

    but recordset and database dont work there

    Does anyone know any good sites for learning about Databases with VB 6.0

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

    Re: Can someone help me?

    Check out the Database FAQ on our fourm - http://www.vbforums.com/showthread.php?t=337051

    There is a link to a good ADO tutorial.
    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
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Can someone help me?

    What version of VB are you using?

  4. #4
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Can someone help me?

    probably u missed adding Reference for the ADO connection!!!
    Show Appreciation. Rate Posts.

  5. #5

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    What would the code be for searching a ADO Database?

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

    Re: Can someone help me?

    Quote Originally Posted by lavarock09
    What would the code be for searching a ADO Database?
    There are MS Access datbases; MS SQL Server databases; Oracle databases; MySQL databases, but there is no such thing as a ADO database.

    ADO is a method used to connect to an existing database.

    Lets get connected, and then we can talk about searching.

    Set a reference the Microsoft ActiveX Object Library, and then run this code.
    VB Code:
    1. Dim ADOCn As ADODB.Connection
    2. Dim ConnString As String
    3.  
    4. ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    5.         "Data Source=" & App.Path & "\yourdatabasename.mdb;" & _
    6.         "Persist Security Info=False"
    7.  
    8. Set ADOCn = New ADODB.Connection
    9. ADOCn.ConnectionString = ConnString
    10. ADOCn.Open ConnString

  7. #7

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    sorry, my mistake,

    I mean MS Access Database

    I've connected and all, I just need to search it

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

    Re: Can someone help me?

    VB Code:
    1. Dim adoRS As ADODB.Recordset
    2. Dim sSQL As String
    3.  
    4. Set adoRS = New ADODB.Recordset
    5. sSQL = "SELECT * FROM table WHERE " 'dont know what you want to search for so
    6. 'i have no idea what to use as an example in a WHERE clause, but here is
    7. 'a start that will give you a recordset with all records matching your SQL
    8. 'statement
    9. adoRS.Open sSQL, ADOCn
    Now that you have a bunch of records, what do you want to do to/with them?

  9. #9

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    Display them in a List box and when you choose one it displays it in the controls

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

    Re: Can someone help me?

    Quote Originally Posted by lavarock09
    Display them in a List box
    What are the "them"? What are you searching for?
    Quote Originally Posted by lavarock09
    and when you choose one it displays it in the controls
    What controls? How does "it" (whatever "it" is) display?

  11. #11

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    THEM = a string, e.g. Chris, Bill, g7463, what the search has returned

    IT = The option you have chosen from the listbox

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

    Re: Can someone help me?

    Quote Originally Posted by lavarock09
    THEM = a string, e.g. Chris, Bill, g7463, what the search has returned

    IT = The option you have chosen from the listbox
    Ok, and what "controls" would it be displayed in once it got selected?

    Answer that one last question and I can give you sample code to do all this stuff which you should be able to easily modifiy to suit your specific needs.

  13. #13

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    the controls are text boxes

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

    Re: Can someone help me?

    Ok. From the top, starting with connecting to the database all the way down to display a piece of information in a textbox.
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim ADOCn As ADODB.Connection
    3. Dim ConnString As String
    4. Dim adoRS As ADODB.Recordset
    5. Dim sSQL As String
    6.  
    7. ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    8.         "Data Source=c:\yourdatabase.mdb;" & _
    9.         "Persist Security Info=False"
    10.  
    11. Set ADOCn = New ADODB.Connection
    12. ADOCn.ConnectionString = ConnString
    13. ADOCn.Open ConnString
    14. Set adoRS = New ADODB.Recordset
    15. 'it doesnt look like you need a specific WHERE clause for this situation
    16. 'however, if you did it would look something like
    17. 'WHERE fieldname = 'Chris'
    18. sSQL = "SELECT fieldname FROM tablename "
    19. adoRS.Open sSQL, ADOCn
    20. Do Until adoRS.EOF
    21.     List1.AddItem adoRS.Fields.Item("fieldname").Value
    22.     adoRS.MoveNext
    23. Loop
    24. adoRS.Close
    25. ADOCn.Close
    26. Set ADOCn = Nothing
    27. Set adoRS = Nothing
    28. End Sub
    29.  
    30. Private Sub List1_Click()
    31. Text1.Text = List1.List(List1.ListIndex)
    32. End Sub
    You will need to change:
    yourdatabase.mdb to your datbase name
    fieldname to the name of the field holding the data you are going after
    tablename to the name of the table that holds the field that holds the data you are going after
    I'm using generic control names (List1, Text1, etc). You will need to change those to match the control names you have.

    This, however, should get you on the road to where you want to go.

  15. #15

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    Question 1: would I have to change the SQL statement to include the table name (tbl_master)

    Question 2: would I have to change the SQL statement to include the fieldname (Callsign/Station)

    Quesion 3: I keep getting the error: 'No value given for one or more required parameters' and when I click debug it highlights this: 'adoRS.Open sSQL, ADOCn'

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

    Re: Can someone help me?

    Quote Originally Posted by lavarock09
    Question 1: would I have to change the SQL statement to include the table name (tbl_master)
    Quote Originally Posted by Hack
    You will need to change:
    tablename to the name of the table that holds the field that holds the data you are going after
    Quote Originally Posted by lavarock90
    Question 2: would I have to change the SQL statement to include the fieldname (Callsign/Station)
    Quote Originally Posted by Hack
    You will need to change:
    fieldname to the name of the field holding the data you are going after
    Quote Originally Posted by lavarock09
    Quesion 3: I keep getting the error: 'No value given for one or more required parameters' and when I click debug it highlights this: 'adoRS.Open sSQL, ADOCn'
    Have you made those changes?

  17. #17

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    Yes.

    This is what my code is now

    VB Code:
    1. Private Sub Command2_Click()
    2. Dim ADOCn As ADODB.Connection
    3. Dim ConnString As String
    4. Dim adoRS As ADODB.Recordset
    5. Dim sSQL As String
    6.  
    7. ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    8.         "Data Source=C:\Documents and Settings\Chris\My Documents\VB Logbook\ADO\logbook.mdb;" & _
    9.         "Persist Security Info=False"
    10.  
    11. Set ADOCn = New ADODB.Connection
    12. ADOCn.ConnectionString = ConnString
    13. ADOCn.Open ConnString
    14. Set adoRS = New ADODB.Recordset
    15. 'it doesnt look like you need a specific WHERE clause for this situation
    16. 'however, if you did it would look something like
    17. 'WHERE fieldname = 'Chris'
    18. sSQL = "SELECT 'Callsign/Station' FROM 'tbl_master'"
    19. adoRS.Open sSQL, ADOCn
    20. Do Until adoRS.EOF
    21.     List1.AddItem adoRS.Fields.Item("Callsign/Station").Value
    22.     adoRS.MoveNext
    23. Loop
    24. adoRS.Close
    25. ADOCn.Close
    26. Set ADOCn = Nothing
    27. Set adoRS = Nothing
    28. End Sub

  18. #18

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    but the error has changed.

    'Syntax Error in query. incomplete query clause'

    Sorry for the double post

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

    Re: Can someone help me?

    You don't need the single quotes, but because of the / in the field name, you might need brackets. Try this first:
    VB Code:
    1. sSQL = "SELECT Callsign/Station FROM tbl_master
    Single quotes are needed around string data elements, not field or table names.

    If that still gives you heartburn, but brackets around Callsign/Station (i.e., [Callsign/Station] )

  20. #20

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    Thanks you,

    But now it needs a bit more added to it.

    I need it to search for what is in the text box, (Text10) so I did this

    VB Code:
    1. sSQL = "SELECT [Callsign/Station] FROM tbl_master WHERE [Callsign/Station] = 'Text10.Text'"

    But that didn't work

    So, can you help me.

    I also need it so that when you click on the result in the listbox it updates all the other boxes (text1 to text9)

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

    Re: Can someone help me?

    Quote Originally Posted by lavarock09
    Thanks you,

    But now it needs a bit more added to it.

    I need it to search for what is in the text box, (Text10) so I did this

    VB Code:
    1. sSQL = "SELECT [Callsign/Station] FROM tbl_master WHERE [Callsign/Station] = 'Text10.Text'"

    But that didn't work

    So, can you help me.

    I also need it so that when you click on the result in the listbox it updates all the other boxes (text1 to text9)
    Close, very close. Now you need the single quotes.
    VB Code:
    1. sSQL = "SELECT [Callsign/Station] FROM tbl_master WHERE [Callsign/Station] = '" & Text10.Text & "' "

    Update all the textboxes how? With the exact same thing?

  22. #22

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    Well, I'll do an example

    My Database

    Callsign/Station : Date (Text1) : Frequency (Text2) : Start Time (Text3) : End Time (Text4) : Mode (Text5) : Power (Text6) : I forget (Text7) : I forget again (Text8) : Comments (Text9)

    They all have bits of data, I need these updating with everything

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

    Re: Can someone help me?

    You are going to have issues because of how you built your table. Date is a reserved word in every programming language I've ever seen. Never used reserved words for field names. That MUST be put in brackets. You have spaces in your field names. Never put spaces in your field names because they are a pain to deal with. Those fields also must be put in brackets.

    Based on the query that you ran, you should get one recordback in your recordset, so to update your textboxes you can do something like this:
    VB Code:
    1. Text1.Text = adoRs.Fields.Item("[Date]").Value
    2. Text2.Text = adoRs.Fields.Item("[Start Time]").Value
    3. 'Im not going to write out 10 statements but you get what I mean.

  24. #24

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    Scrap that Idea for a moment

    How would I make it so that when I select the result from the search It makes a text box display the ID of the row that the result is on

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

    Re: Can someone help me?

    Is ID a field in your table that can be brought back with your SELECT statement?

  26. #26

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    yes, It is the number of the row/entry in the database

    I have managed to get that but...

    I want some code that will-

    1: Give me all the data on the row with a certain ID,

    so this means,

    1: I do a search for whatever string in the Callsign/Station column in the database (Done!)
    2: It displays all rows with that data in that column, that meaning Callsign/Station (Done!)
    3: I click on the result and it gives me the Id of the row it is on in a textbox. (Not Done!)
    4: I then click on a button and it updates all textboxes with the information on the row (Not Done!)

    Steps 3 and 4 need coding, but I wouldn't have a clue how to do it, can you help?

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

    Re: Can someone help me?

    When you say "click on the result", where is the result? Is it in your listbox?

    If so, then you would need to requery, but that shouldn't be a problem. But, before I post an example I want to make sure I understand what is going on.

  28. #28

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    I search for something in the Callsign clolumn of the table

    It comes up with the results in the list box,

    I click on one of the results in the listbox

    In one text box It gives the Callsign
    in another text box it gives the ID of the row that the Callsign Has come from

    keep in mind though that I may end up searching for one thing e.g. Y6FGH and getting back 10 different results because Y6FGH may be in the table column, Callsign, more than once

    Then I press a but button and It then updates all the textboxes on the form, Date (text1.text), time etc. with the data from the row with the row Id in the previous textbox

    Do you understand?
    Last edited by lavarock09; Sep 26th, 2005 at 02:37 PM.

  29. #29

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    *bump*

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

    Re: Can someone help me?

    Quote Originally Posted by lavarock09
    I search for something in the Callsign clolumn of the table

    It comes up with the results in the list box,

    I click on one of the results in the listbox

    In one text box It gives the Callsign
    in another text box it gives the ID of the row that the Callsign Has come from
    Assuming your listbox is populated with call signs, code for this would be something along the lines of
    VB Code:
    1. SELECT Id, CallSign FROM tbl_master WHERE CallSign = '" & List1.List(List1.ListIndex) & "' "
    2. adoRS.Open sSQL, ADOCn
    3. Text1.Text = adoRS.Fields.Item("ID").Value
    4. Text2.Text = adoRS.Fields.Item("CallSign").Value
    Quote Originally Posted by lavarock09
    Do you understand?
    I hope so but I'm not really sure. Did what I post make sense?

  31. #31

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    Let me just show you this,

    this is the code I have got,

    VB Code:
    1. Dim ADOCn As ADODB.Connection
    2. Dim ConnString As String
    3. Dim adoRS As ADODB.Recordset
    4. Dim sSQL As String
    5.  
    6. ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    7.         "Data Source=C:\Documents and Settings\Chris\My Documents\VB Logbook\ADO\logbook.mdb;" & _
    8.         "Persist Security Info=False"
    9.  
    10. Set ADOCn = New ADODB.Connection
    11. ADOCn.ConnectionString = ConnString
    12. ADOCn.Open ConnString
    13. Set adoRS = New ADODB.Recordset
    14. 'it doesnt look like you need a specific WHERE clause for this situation
    15. 'however, if you did it would look something like
    16. 'WHERE fieldname = 'Chris'
    17. sSQL = "SELECT ID, [Callsign/Station] FROM tbl_master WHERE [Callsign/Station] = '" & List1.List(List1.ListIndex) & "' "
    18. adoRS.Open sSQL, ADOCn
    19. Combo2.Text = adoRS.Fields.Item("ID").Value
    20. combo1.Text = adoRS.Fields.Item("Callsign/Station").Value
    21. adoRS.Open sSQL, ADOCn
    22. Do Until adoRS.EOF
    23.     List1.AddItem adoRS.Fields.Item("Callsign/Station").Value
    24.     List2.AddItem adoRS.Fields.Item("ID").Value
    25.  adoRS.MoveNext
    26. Loop
    27. adoRS.Close
    28. ADOCn.Close
    29. Set ADOCn = Nothing
    30. Set adoRS = Nothing

    Is there anything wrong with it?

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

    Re: Can someone help me?

    Quote Originally Posted by lavarock09
    Let me just show you this,

    this is the code I have got,

    VB Code:
    1. Dim ADOCn As ADODB.Connection
    2. Dim ConnString As String
    3. Dim adoRS As ADODB.Recordset
    4. Dim sSQL As String
    5.  
    6. ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    7.         "Data Source=C:\Documents and Settings\Chris\My Documents\VB Logbook\ADO\logbook.mdb;" & _
    8.         "Persist Security Info=False"
    9.  
    10. Set ADOCn = New ADODB.Connection
    11. ADOCn.ConnectionString = ConnString
    12. ADOCn.Open ConnString
    13. Set adoRS = New ADODB.Recordset
    14. 'it doesnt look like you need a specific WHERE clause for this situation
    15. 'however, if you did it would look something like
    16. 'WHERE fieldname = 'Chris'
    17. sSQL = "SELECT ID, [Callsign/Station] FROM tbl_master WHERE [Callsign/Station] = '" & List1.List(List1.ListIndex) & "' "
    18. adoRS.Open sSQL, ADOCn
    19. Combo2.Text = adoRS.Fields.Item("ID").Value
    20. combo1.Text = adoRS.Fields.Item("Callsign/Station").Value
    21. adoRS.Open sSQL, ADOCn
    22. Do Until adoRS.EOF
    23.     List1.AddItem adoRS.Fields.Item("Callsign/Station").Value
    24.     List2.AddItem adoRS.Fields.Item("ID").Value
    25.  adoRS.MoveNext
    26. Loop
    27. adoRS.Close
    28. ADOCn.Close
    29. Set ADOCn = Nothing
    30. Set adoRS = Nothing

    Is there anything wrong with it?
    Well, you can remove the comments I made about the WHERE clause, but other than that it looks good.

    Does it do what you need it to do?

  33. #33

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    Well...this is the code for the button that I press that displays the Callsign In one list box and the ID of the row that the callsign is on in another lisybox,

    but Keep getting this error as ot doesn't like this line of code

    VB Code:
    1. combo1.Text = adoRS.Fields.Item("Callsign/Station").Value

    I get this error and it highlights it

    Item cannot be found in the collection corresponding to the requested name or ordinal

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

    Re: Can someone help me?

    Quote Originally Posted by lavarock09
    Well...this is the code for the button that I press that displays the Callsign In one list box and the ID of the row that the callsign is on in another lisybox,

    but Keep getting this error as ot doesn't like this line of code

    VB Code:
    1. combo1.Text = adoRS.Fields.Item("Callsign/Station").Value

    I get this error and it highlights it
    I just knew that / was going to cause trouble. Wierd characters like that tend to freak out querys. Since you already have the field created, encapsulate it in brackets. That should help.

  35. #35

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    you mean like this?

    VB Code:
    1. combo1.Text = adoRS.Fields.Item("[Callsign/Station]").Value

    If so...

    It didn't work

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

    Re: Can someone help me?

    Can you do
    VB Code:
    1. Msgbox adoRS.Fields.Item("[Callsign/Station]").Value

  37. #37

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    can you just tell me where to put this code.

    I've put it in List1_Click

    but I get the same error

  38. #38

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Can someone help me?

    I can't thank you enough Hack.

    But I think I have done everything I needed, but It wouldn't of been possible without you so,

    Thank You! (this is a rare occasion, I'm using a smiley)


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