Results 1 to 10 of 10

Thread: Match The Data

  1. #1

    Thread Starter
    Addicted Member g.mie's Avatar
    Join Date
    Jan 2001
    Location
    EarTh
    Posts
    134

    Talking Match The Data

    Hello guys..

    I have problem here. How to match the data from ComboBox to Database. Detail information as below:-

    1. ComboBox - contain letter from A to Z
    2. SQL database - contain a few letter (ex: A, B, F and G)

    I want to hide letter A, B, F and G in ComboBox. Because I want to make sure there are no same letter in database when I save it later on.

    So, first how to match letter in database to letter in ComboBox and
    second hide letter in ComboBox when it match.

    Plz somebody help. I'm urgent on it.

    TQ
    Last edited by g.mie; Aug 13th, 2001 at 07:40 PM.

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    ooookay, this one ain't tested, but should give the general idea if I've buggered the code :
    Code:
    Dim strSQL as string
    Dim intCounter as integer
    
    strSQL = "SELECT * FROM TableName WHERE Column1 =" &  _
                   "'" & combo1.list(0) & "'"
    
    For intCounter = 1 to Combo1.listcount - 1
       strSQL = strSQL & " OR " & "'" & combo1.list(intCounter) & "'"
    Next intCounter
    Will give you a SQL string you can use to match the combobox & the database.

    As I understand it, why do you want to put A-Z in the combobox to start with, you could access the database & grab the recordset of the table (RS) then use this type of thing :
    Code:
    Rs.movefirst
    
    Do while not Rs.EOF
       Combo1.additem Rs!Column1
       Rs.Movenext
    Loop

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    here is my contribution...

    use a table which contains ALL the letters and pick out all those which don't occur on the main table.
    Mark
    -------------------

  4. #4

    Thread Starter
    Addicted Member g.mie's Avatar
    Join Date
    Jan 2001
    Location
    EarTh
    Posts
    134

    I'll try it

    TQ,

    But I'll try later. Time to go home now .

    See U both later.

    Bye

  5. #5

    Thread Starter
    Addicted Member g.mie's Avatar
    Join Date
    Jan 2001
    Location
    EarTh
    Posts
    134

    Not Work - alex_read

    Hello alex_read

    I think it not work. I give more info about my project:

    1. Table name : cs_roster_detail
    2. Fields name : id, queue(fields to save letter)
    3. ComboBox name : cboQueue(contain a list of Letter, A-Z).

    And for Mark Sreeves, I can't add more table into my project so it mean that I cannot use your samle. May be U have another idea.

    Plz help me on this.

  6. #6
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Ignore mine for the moment as Marks sample's fine to go from -
    not every day you produce working code Mark, but this one's !

    g.mie, can't see why Mark's don't work on yours make sure you put his database under the "C:" path, or if you have it in the same path as the vb app from the zip file, change the following :
    Code:
    Private Sub Form_Load()
        Set db = DAO.OpenDatabase(App.Path & "\letter.mdb")
    
        LoadCombo
    End Sub
    Other than that, check the Project > References menu to see if it has a reference to the Microsoft DAO 3.5 object library.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  7. #7
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Originally posted by alex_read
    Ignore mine for the moment as Marks sample's fine to go from -
    not every day you produce working code Mark, but this one's !
    I presume that you mean I don't usually post a complete working project!


    The dude is saying that he can't add another table to the database.

    I don't know why on earth that could be.
    Mark
    -------------------

  8. #8
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Try using this for your project :

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  9. #9

    Thread Starter
    Addicted Member g.mie's Avatar
    Join Date
    Jan 2001
    Location
    EarTh
    Posts
    134

    Progress

    I'm work on it now. If anything I shout U all back.

  10. #10
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    There's probably a better way of doing this but you could create a "reference" table and delete it afterwards

    Code:
    Option Explicit
    Dim db As Database
    
    Private Sub Form_Load()
    Set db = DAO.OpenDatabase("c:\letter.mdb")
    
    Dim rst As Recordset
    Dim strSQL As String
    Dim i As Integer
    
    strSQL = "CREATE TABLE tblChars " _
        & "(ch TEXT);"
    
    db.Execute strSQL
    
    Set rst = db.OpenRecordset("tblChars")
    
    With rst
    For i = 65 To 90
      .AddNew
      !ch = Chr(i)
      .Update
    Next i
    .Close
    
    End With
    Set rst = Nothing
    
    LoadCombo
    End Sub
    Private Sub LoadCombo()
    Dim rst As Recordset
    Dim strSQL As String
    
    strSQL = "SELECT DISTINCTROW [tblChars].*" & _
    " FROM tblChars LEFT JOIN Table1 ON [tblChars].[ch] = [Table1].[f1] " & _
    " WHERE ([Table1].[f1] Is Null); "
    
    Combo1.Clear
    Set rst = db.OpenRecordset(strSQL)
    With rst
      While Not .EOF
        Combo1.AddItem !ch
        .MoveNext
      Wend
      .Close
    End With
    
    Set rst = Nothing
    
    
    Combo1.ListIndex = 0
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    db.Execute "DROP TABLE tblChars"
    db.Close
    End Sub
    Mark
    -------------------

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