Results 1 to 20 of 20

Thread: [RESOLVED] DataCombo/MySQL

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    [RESOLVED] DataCombo/MySQL

    Hi Guys. I have a form that can successfully access a MySQL database. I have two DataCombo's on this form. They are both set up in the same way but to access a different column in the database.

    The first DataCombo has a name called DateUpdate. The datasource has a value of Adodc1 (also has the control or what ever you all it on the form). The DataField is set to the column I want. The DataFormat is set to the format I want. However, when I run the form, ONLY the first entry in the database is placed into the DataCombo, nothing after that. The test database has two entries for testing. The second entry does not go in.

    This is the same for the other DataCombo on the form. Of course, each DataCombo has a different name. And is set in the same way but to access a different column.

    But when I added the following, the form doesn't come up, just shows the error message below and then the app closes
    VB Code:
    1. Do While Not rs.EOF
    2. DateUpdate.AddItem rs(0)
    3. rs.MoveNext
    4. Loop
    5.  
    6. Do While Not rs.EOF
    7. TimeUpdate.AddItem rs(0)
    8. rs.MoveNext
    9. Loop

    Which I found on a thread in here a moment ago and was given the following error message:

    Compile error:
    Method or data memeber not found.

    .AddItem for the first Do While was highlighted.

    The complete sub is:
    VB Code:
    1. Private Sub Form_Load()
    2. Dim SQL As String
    3. Dim conn As ADODB.Connection
    4. Set conn = New ADODB.Connection
    5.  
    6. Dim rs As ADODB.Recordset
    7. Set rs = New ADODB.Recordset
    8.  
    9. conn.CursorLocation = adUseClient
    10. conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
    11.   & "SERVER=00.00.000.000;" _
    12.   & "DATABASE=paddy_mbrblog;" _
    13.   & "UID=paddy_mbrblog;" _
    14.   & "PWD=mbrblog;" _
    15.   & "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 16384
    16.  
    17. conn.Open conn.ConnectionString
    18. SQL = "SELECT * FROM blog WHERE Username = '" & txtUpdateEntryUsername & "'"
    19.  
    20. Do While Not rs.EOF
    21. DateUpdate.AddItem rs(0)
    22. rs.MoveNext
    23. Loop
    24.  
    25. Do While Not rs.EOF
    26. TimeUpdate.AddItem rs(0)
    27. rs.MoveNext
    28. Loop
    29.  
    30. rs.Open SQL, conn, adOpenStatic, adLockReadOnly
    31.  
    32. rs.Close
    33.     Set rs = Nothing
    34.  
    35. conn.Close
    36.     Set conn = Nothing
    37. End Sub

    Please advise if you can. (DataMember property does not have anything in it and doesnt allow me to add anything either)

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: DataCombo/MySQL

    Edit out your ip address, user name, and PASSWORD. And, you might want to change it also.

    unless you already did

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: DataCombo/MySQL

    Quote Originally Posted by dglienna
    Edit out your ip address, user name, and PASSWORD. And, you might want to change it also.

    unless you already did

    Ops, forgot about that. It's ok though, the real database is going to have different settings. This is only a test one. Has nothing important in it.

    Still having a hard time with the population.

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: DataCombo/MySQL

    You have to use the same name as the table in your SQL
    VB Code:
    1. SQL = "SELECT * FROM blog WHERE Username = '" & txtUpdateEntryUsername & "'"

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: DataCombo/MySQL

    Also, you need a .movefirst before you can go thru it a second time.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: DataCombo/MySQL

    Quote Originally Posted by dglienna
    You have to use the same name as the table in your SQL
    VB Code:
    1. SQL = "SELECT * FROM blog WHERE Username = '" & txtUpdateEntryUsername & "'"
    blog is the table

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: DataCombo/MySQL

    Quote Originally Posted by dglienna
    Also, you need a .movefirst before you can go thru it a second time.
    Is this correct?

    VB Code:
    1. Do While Not rs.EOF
    2. rs.MoveFirst
    3. DateUpdate.AddItem rs(0)
    4. rs.MoveNext
    5. Loop
    6.  
    7. Do While Not rs.EOF
    8. rs.MoveFirst
    9. TimeUpdate.AddItem rs(0)
    10. rs.MoveNext
    11. Loop

    Update:
    VB Code:
    1. DateUpdate.AddItem rs(0)

    Compile error:
    Method or data member not found

    Highlighted: .AddItem

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: DataCombo/MySQL

    Nope, you can't keep moving to the first, or you'll be in a loop

    VB Code:
    1. Do While Not rs.EOF
    2. rs.MoveFirst
    3. DateUpdate.AddItem rs(0)
    4. rs.MoveNext
    5. Loop
    6.  
    7. [COLOR=Red]rs.MoveFirst
    8. [/COLOR]
    9. Do While Not rs.EOF
    10. TimeUpdate.AddItem rs(0)
    11. rs.MoveNext
    12. Loop

  9. #9
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: DataCombo/MySQL

    And, if you want to use the same field for both combo boxes, then you might want to apply some formatting as you add them.

    VB Code:
    1. additem format(rs.fields(0),"HH:mm")

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: DataCombo/MySQL

    Quote Originally Posted by dglienna
    Nope, you can't keep moving to the first, or you'll be in a loop

    VB Code:
    1. Do While Not rs.EOF
    2. rs.MoveFirst
    3. DateUpdate.AddItem rs(0)
    4. rs.MoveNext
    5. Loop
    6.  
    7. [COLOR=Red]rs.MoveFirst
    8. [/COLOR]
    9. Do While Not rs.EOF
    10. TimeUpdate.AddItem rs(0)
    11. rs.MoveNext
    12. Loop
    VB Code:
    1. Do While Not rs.EOF
    2. rs.MoveFirst
    3. DateDelete.AddItem rs(0) <-----error here for .AddItem
    4. rs.MoveNext
    5. Loop
    6.  
    7. rs.MoveFirst
    8. Do While Not rs.EOF
    9. TimeDelete.AddItem rs(0)
    10. rs.MoveNext
    11. Loop

    Compile error:
    Method or data member not found

    Highlighted: .AddItem

  11. #11
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: DataCombo/MySQL

    Formatted:
    VB Code:
    1. additem format(rs.fields(0),"HH:mm")
    Unformatted
    VB Code:
    1. additem rs.fields(0)

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: DataCombo/MySQL

    Quote Originally Posted by dglienna
    Formatted:
    VB Code:
    1. additem format(rs.fields(0),"HH:mm")
    Unformatted
    VB Code:
    1. additem rs.fields(0)
    The formatting is done through the properties window using DataFormat property.

    Still getting the same error problem with .AddItem even when I change it to rs.Fields(0)

    Even if I do:
    rs.Fields("Column_Name") I still get the same error

  13. #13
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: DataCombo/MySQL

    I use this with no problem:

    VB Code:
    1. Do While rec.EOF = False
    2.     RecID = rec.Fields(0)
    3.     rec.MoveNext
    4.   Loop

    I am only returning one value, so that is kind of unnecessary. EOF is true after the first value.

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: DataCombo/MySQL

    Quote Originally Posted by dglienna
    I use this with no problem:

    VB Code:
    1. Do While rec.EOF = False
    2.     RecID = rec.Fields(0)
    3.     rec.MoveNext
    4.   Loop

    I am only returning one value, so that is kind of unnecessary. EOF is true after the first value.
    There is always going to be more than one value here so EOF is going to be needed I am sure.

    VB Code:
    1. Do While Not rs.EOF = False
    2. rs.MoveFirst
    3. DateDelete.AddItem rs.Fields(0)
    4. rs.MoveNext
    5. Loop
    6.  
    7. rs.MoveFirst
    8. Do While Not rs.EOF = False
    9. TimeDelete.AddItem rs.Fields(0)
    10. rs.MoveNext
    11. Loop

    or

    VB Code:
    1. Do While rs.EOF = False
    2. rs.MoveFirst
    3. DateDelete.AddItem rs.Fields(0)
    4. rs.MoveNext
    5. Loop
    6.  
    7. rs.MoveFirst
    8. Do While rs.EOF = False
    9. TimeDelete.AddItem rs.Fields(0)
    10. rs.MoveNext
    11. Loop

    STILL produces same error. DataCombo is a pain in my A$$

  15. #15
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: DataCombo/MySQL

    Oh, thought you were using a ComboBox, which has the additem property. I see that a datacombo is a bound (evil) control

    If you insist, though, here is an excerpt:

    In the Properties window, set the properties of the DataCombo control as shown in the table below.Property Setting
    Name dcbSuppliers
    DataSource adoDataSource
    DataField SupplierID
    RowSource adoRowSource
    ListField CompanyName
    BoundColumn SupplierID

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: DataCombo/MySQL

    Quote Originally Posted by dglienna
    Oh, thought you were using a ComboBox, which has the additem property. I see that a datacombo is a bound (evil) control

    If you insist, though, here is an excerpt:
    I would use the ComboBox but cant find it hehe

  17. #17
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: DataCombo/MySQL

    Fifth from the top, on the left, next to the listbox. That will simplify things greatly! Set it to drop-down, and set the text to a message like "Choose Time"

  18. #18
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: DataCombo/MySQL

    Try this:
    Attached Files Attached Files

  19. #19

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: DataCombo/MySQL

    Quote Originally Posted by dglienna
    Fifth from the top, on the left, next to the listbox. That will simplify things greatly! Set it to drop-down, and set the text to a message like "Choose Time"
    Replaced DataCombo with ComboBox now.

    Both are set to 0 - Dropdown Combo

    The one called DateDelete has a message of Choose Date
    The one called TimeDelete has a message of Choose Time

    DateDelete is going to house the dates
    TimeDelete is going to house the times

    The code you enclosed also doesnt work with mysql by what i can tell but when i did it, it added 0-100 in both of them. just have to modify to work with records.

  20. #20

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