Results 1 to 6 of 6

Thread: Finding a value

  1. #1
    Join Date
    Feb 2004
    Posts
    15

    Unanswered: Finding a value

    Hi, I am currently having a problem locating a true/false
    value from a table based on the values in two other fields.
    I have a combo box with clients names which after
    update affects a list box contents. Sometimes this list box contains
    more than one value. Depending on which value of this box the
    user clicks on I want the database to tell me whether or
    not this is true / false for that particular record.
    Can somebody please help?!
    Thank you
    Jon

  2. #2
    Join Date
    Aug 2002
    Location
    Cambridge, England
    Posts
    47
    Try something along these lines

    Code:
    Dim itm as Variant
    Dim lst as listbox
    Dim MyTrueOrFalse as Boolean
    
    lst = MyForm!MyListbox
    
    For Each itm In lst.ItemsSelected
            MyTrueOrFalse = lst.Column(ColumnNumberOfBooleanValue, itm)
    Next itm

  3. #3
    Join Date
    Feb 2004
    Posts
    15

    reply

    Sorry its late reply, I don't understand what you mean when you use booleans and variants and columns. Can you help?

  4. #4
    Join Date
    Sep 2003
    Location
    T.O.
    Posts
    326
    This is the approach that I took. Keep in mind that I had to make some assumptions about your question because I didn't quite understand it.

    I believe you are looking to find out when your multi-select list box has more than one item selected. This is your True condition, otherwise, you are looking for False:

    Dim ctl As Control, varItm As Variant
    Dim i As Integer, boolMulti As Boolean
    Set ctl = Me.YourListBoxNameGoesHere
    For Each varItm In ctl.ItemsSelected
    i = i + 1
    Next varItm
    If i > 1 Then
    boolMulti = True
    End If
    MsgBox boolMulti
    i = 0
    All code ADO/ADOX unless otherwise specified.
    Mike.

  5. #5
    Join Date
    Feb 2004
    Posts
    15
    I have 3 fields in a table which are represented on a form.
    This form contains a combo box full of client names, when the user selects a client, a list box (containing box numbers) appears with values for that specific client. For example 1 or maybe more different box numbers appear. The third field contains true/false for whether that file is missing or not. When the user clicks on one of these values (box numbers), I want the database to look at that particular record (using the combo box value and the listbox value clicked on) to see if that file is missing (true/false).
    Thank you

  6. #6
    Join Date
    Sep 2003
    Location
    T.O.
    Posts
    326
    If that's your requirement, I think nstaward has answered your question.

    Booleans and Variants are variable datatypes in the context provided, the column is a property.

    I think you may want to look into a Beginning VBA for Access book (imho, Wrox/McGraw Hill/Sybex are all good publishers, not QUE) if you're having trouble reading the code. It's fairly simple from a VBA perspective, but rather difficult if your xp with VBA is nil.

    To see if it would solve your immediate problem, create a command button, go to the properties tab, on the Event tab Choose the drop-down for the OnClick event, when the ellipses appear select that.

    Then copy and paste nstaward's code in between Private Sub and End Sub making sure you replace 'MyForm' with the name of your actual form and 'MyList' with the name of your actual listbox.

    Append MsgBox MyTrueOrFalse on a new line after the code.

    Hope this works. Anything beyond this, imho, is beyond the scope of the forum (i.e., teaching VBA from the ground-up) and falls into the region of getting a book to introduce these concepts.
    All code ADO/ADOX unless otherwise specified.
    Mike.

Posting Permissions

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