Results 1 to 40 of 40

Thread: checkboxes arggghhhh!!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Angry

    I have this scenario: I read a access database, then loop like this:
    Do
    txtID = "" & rs!ID
    txtCustomer = "" & rs!Customer
    txtCustomerID = "" & rs!CustomerID
    txtPostCodes = "" & rs!POSTCODES
    txtIGN = "" & rs!IGN
    txtOwnMasterDatabase = "" & rs!OwnMasterDatabase
    txtWebDBType = "" & rs!WebDBType
    txtDongle = "" & rs!Dongle
    txtCarriers = "" & rs!Carrier
    txtTriQuad = "" & rs!TriQuad
    txtumNumberUsers = "" & rs!umNumberUsers
    txtumPassword = "" & rs!umPassword
    txtumDistance = "" & rs!umDistance
    txtumTariff = "" & rs!umTariff
    txtumCosts = "" & rs!umCosts
    txtumMultipleLogin = "" & rs!umMultipleLogin
    txtISPreProccessorType = "" & rs!SetPreProccessor
    rs.MoveNext
    Loop Until rs.EOF
    I then have check boxes 12 for instance to represent each customer, what i would like to do is loop until a check represents the txtCustomerID... any help please???

    Many thanks

  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    I'm not really sure what you are trying to do, but.

    Are you saying that when a user clicks 1 of 12 checkboxes you want to find and display the coresponding customer?

    If the customers ID is 1-12 then that is easy, you could use a control array.

    Other wise look into using the "Tag" property of the check box. You could store each customers ID in the Tag of an individual checkbox.
    Iain, thats with an i by the way!

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Exclamation check boxes

    Easy to you perhaps, but when you've been working with VB for 5 minutes a week, not so... could you elaborate please..

    Many thanks.

  4. #4
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    If the customers ID's are 1 - 12 Then :

    create a checkbox on your form. Copy it and paste it to the form. this will create a control array. Repeat until you have 12 check boxes.

    These will be numbered 0 - 11.

    Now when the user clicks on the checkbox, you use the click event to find the customer

    Code:
    Private Sub Check1_Click(Index As Integer)
      findCust (index)
    End Sub
    
    private sub findCust (iCust as Integer)
    
      rs.movefirst
      do until (iCust = rs!CustomerID) or (rs.eof)
        rs.movenext
      loop
       
      'now display the data
    End Sub

    If the customers ID is going to be like "AB12Z" or something then :

    When you load the form you will have to get all of the customers ID's out of the record set and place them in the Tag property of the checkboxs.

    Code:
    private sub getCustId()
      
      i = 0
      do until rs.eof = true
        check1(i).Tag = rs!CustomerID
        i = i + 1
        rs.movenext
      until
    
    End Sub
    
    Private Sub Check1_Click(Index As Integer)
      findCust (check1(index).Tag)
    End Sub
    
    private sub findCust (iCust as String)
    
      rs.movefirst
      do until (iCust = rs!CustomerID) or (rs.eof)
        rs.movenext
      loop
       
      'now display the data
    End Sub
    Iain, thats with an i by the way!

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Talking check boxes

    I shall try this..

    Many thanks


  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Exclamation check boxes

    Yes, txtCustomerID returns a string..

    ok!

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Question check boxes

    private sub getCustId()

    i = 0
    do until rs.eof = true
    check1(i).Tag = rs!CustomerID
    i = i + 1
    rs.movenext
    until ' Shouldn't this be 'Loop'
    End Sub

  8. #8
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    alright, don't get arsy with me.

    When i am writing code of the top of my head like that i often revert back to my days of pascal, as that is the first language i learnt.

    Sorry.
    Iain, thats with an i by the way!

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Question check boxes

    What if i had multiple selections

  10. #10
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658

    Question Explain?

    What do you mean by multiple selections, and what would you like to do with them?
    Iain, thats with an i by the way!

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Question check boxes

    What part of the world are you from.. i've never heard of that saying before.. anyhow sorry for being arsy?? yeh, sounds great.

    Cheers


  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Wink check boxes

    This works.. thanks for that.. last question, what if i selected multiple check boxes?

  13. #13
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Oh yeah i forgot some info. You probably already know any way.

    When the check box is clicked on you will have to check the value to see if it is checked or not. If it is checked then display customer, if it is unchecked then clear info.

    If you clicked a second box, it would just show the most recently clciked check boxes customer.

    if you only want one box at a time checked i suggest using radio buttons.


    Just to answer your other question, i'm in England. i think it might be spelled arsey actually. Not really sure.
    Iain, thats with an i by the way!

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Cool check boxes

    Yep, me again, so if i did have ticked say, 4 check boxes, this method is useless?

    Regards

    ps: What if i wanted a select all box as well.?

  15. #15
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    How do you intend to display multiple customers at the same time. Please explain what you want to achieve
    Iain, thats with an i by the way!

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Post check boxes

    On first selected check box, create an app for that customer, on the other check box selection do the same and so on..

    Many thanks

  17. #17
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    I can't see a problem with that. By app, do you mean shell a new application, or a new form?

    You could create any number of instances of a customer detail form.
    Iain, thats with an i by the way!

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Post check boxes

    No, an application is built per customer so the scenario is

    check1(3) say smith
    build application
    repeat until none selected

    Hope this helps


  19. #19
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    i'm begining to get the picture now. Let me see if i have got it right.

    You have (lets say) 12 checkboxes.
    The user can click any number of these.
    When they have done selecting, then you want to hit a command button (GO) that will start the app building.

    Right? If not the following will be a load of useless crap.

    When they hit the GO button you you loop thorugh all of the 12 check boxes and check the value. If the box is checked then you call the find cust, then you build yuor app, or whatever.

    Code:
    Private Sub cmdGO_Click()
      Dim i As Integer
    
      For i = 0 To 11
        If check(i).value = vbChecked Then
          If findCust(check(i).tag) = True Then
            'build app or whatever
          Else
            Msgbox "The Customer was not found!"
          End If
        End If
      Next i
    
    End Sub
    
    
    Private Function findCust (iCust as String) As Boolean
      rs.movefirst
      
      Do Until (findCust = True) or (rs.EOF)
        If iCust = rs.CustomerID Then
          findCust = True
        End If
        rs.MoveNext
      Loop
    
    End Sub
    Iain, thats with an i by the way!

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Talking check boxes

    Thanks for that, i'll try it!!

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Post check boxes

    Can the for loop not be as restricted ie: be the length of how many check boxes their are?

    Regards

  22. #22
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Of course it can.

    Code:
    For i = Check1.LBound To Check1.UBound
      'blah blah blah
    Next i
    Iain, thats with an i by the way!

  23. #23

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Exclamation check boxes

    Where was we up to... ahhh! is this an initialisation.?

  24. #24
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658

    Smile Hello again.

    Pardon? What do you mean?
    Iain, thats with an i by the way!

  25. #25

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Exclamation check boxes

    After a weekend of booze, i can understand that reply

    For i = Check1.LBound To Check1.UBound
    'blah blah blah
    Next i

    Is this an initialisation process?

  26. #26
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    You asked if the for loop can be for the number of checkboxes there are.

    check1.lbound gives you the lowest number in the control array (0 or 1 probably)

    check1.ubound gives you the highest number in the control array (if you have 12 boxes, then 11 if you start at 0 or 12 if you start at 1)

    So the loop will go through each checkbox you have, without hardcoding a number. This will allow you to change the number of checkboxes, without changing the loop code.

    Code:
    Private Sub cmdGO_Click()
      Dim i As Integer
    
      For i = Check1.LBound To Check1.Ubound
        If check(i).value = vbChecked Then
          If findCust(check(i).tag) = True Then
            'build app or whatever
          Else
            Msgbox "The Customer was not found!"
          End If
        End If
      Next i
    
    End Sub
    
    
    Private Function findCust (iCust as String) As Boolean
      rs.movefirst
      
      Do Until (findCust = True) or (rs.EOF)
        If iCust = rs.CustomerID Then
          findCust = True
        End If
        rs.MoveNext
      Loop
    
    End Sub
    Iain, thats with an i by the way!

  27. #27

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Question check boxes

    Hello again,

    I'm having difficulty fitting the formentioned loops to my scenario, my scenario is this

    Do Until (rs.EOF)
    txtID = "" & rs!ID
    txtCustomer = "" & rs!Customer
    txtCustomerID = "" & rs!CustomerID
    txtPostCodes = "" & rs!POSTCODES
    txtIGN = "" & rs!IGN
    txtOwnMasterDatabase = "" & rs!OwnMasterDatabase
    txtWebDBType = "" & rs!WebDBType
    txtDongle = "" & rs!Dongle
    txtCarriers = "" & rs!Carrier
    txtTriQuad = "" & rs!TriQuad
    txtumNumberUsers = "" & rs!umNumberUsers
    txtumPassword = "" & rs!umPassword
    txtumDistance = "" & rs!umDistance
    txtumTariff = "" & rs!umTariff
    txtumCosts = "" & rs!umCosts
    txtumMultipleLogin = "" & rs!umMultipleLogin
    txtISPreProccessorType = "" & rs!SetPreProccessor
    If (iCust = rs!CustomerID) Then

    'build the app
    Else
    End If
    rs.MoveNext
    Loop

    How could i place the code you give me into this scenario:?

    cmdGO_Click()
    Dim i As Integer

    For i = Check1.LBound To Check1.Ubound
    If check(i).value = vbChecked Then
    If findCust(check(i).tag) = True Then
    'build app or whatever
    Else
    Msgbox "The Customer was not found!"
    End If
    End If
    Next i

    End Sub


    Private Function findCust (iCust as String) As Boolean
    rs.movefirst

    Do Until (findCust = True) or (rs.EOF)
    If iCust = rs.CustomerID Then
    findCust = True
    End If
    rs.MoveNext
    Loop

    End Sub



  28. #28
    Guest

    Smile Iain17 he seems abit confused as to what he wnts

    No offence intended.

    But just read through the entire thread and you were doing so well until the final post which kind of doesn't match whats been asked previous.

    Ok if you click a checkbox do you then execute the text loading stuff.?. And how does iCust relate to it.

    Do you want to do something like

    1. Click on Go

    2. Check for any checked boxes

    3. Load the text fields

    4. Generate the app

    5. Repeat 1 through 4 from chkbox(0) to chkbox(11)

    Just trying to clarify things

  29. #29

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Thumbs up check boxes

    EXACTLY!!

  30. #30

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Angry check boxes

    Everything going great but arrrrggghhhh!! again, how do i disable the automatic run when i tick a check box?

  31. #31
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Right.

    Code:
    Private Sub Form_Load()
    
        getCustId
    
    End Sub
    
    Private Sub getCustId()
      Dim i As Integer
    
      i = 0
      rs.movefirst
      do until rs.eof = true
        check1(i).Tag = rs!CustomerID
        i = i + 1
        rs.movenext
      until
    
    End Sub
    
    
    
    Private Sub cmdGO_Click()
      Dim i As Integer
    
      For i = Check1.LBound To Check1.Ubound
        If check(i).value = vbChecked Then
          If findCust(check(i).tag) = True Then
            displayCust
            'build app or whatever
          Else
            Msgbox "The Customer was not found!"
          End If
        End If
      Next i
    
    End Sub
    
    
    Private Function findCust (iCust As String) As Boolean
    
      rs.movefirst
      
      Do Until (findCust = True) Or (rs.EOF)
        If iCust = rs.CustomerID Then
          findCust = True
          Exit Function
        End If
        rs.MoveNext
      Loop
    
    End Sub
    
    
    Private Sub DisplayCust()
    
        txtID = "" & rs!ID 
        txtCustomer = "" & rs!Customer 
        txtCustomerID = "" & rs!CustomerID 
        txtPostCodes = "" & rs!POSTCODES 
        txtIGN = "" & rs!IGN 
        txtOwnMasterDatabase = "" & rs!OwnMasterDatabase 
        txtWebDBType = "" & rs!WebDBType 
        txtDongle = "" & rs!Dongle 
        txtCarriers = "" & rs!Carrier 
        txtTriQuad = "" & rs!TriQuad 
        txtumNumberUsers = "" & rs!umNumberUsers 
        txtumPassword = "" & rs!umPassword 
        txtumDistance = "" & rs!umDistance 
        txtumTariff = "" & rs!umTariff 
        txtumCosts = "" & rs!umCosts 
        txtumMultipleLogin = "" & rs!umMultipleLogin 
        txtISPreProccessorType = "" & rs!SetPreProccessor 
    
    End Sub
    Iain, thats with an i by the way!

  32. #32

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Lightbulb parameters

    Shouldn't displayCust take a parameter?

  33. #33
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Nope. We have already moved to the right posiiton in the recordset, so we just tell the procedure to display whatever is at that current position.
    Iain, thats with an i by the way!

  34. #34

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Smile GLOBALS

    So these variables will have to be global..?
    "i dont like global variables..!!!" Thanks for your help

  35. #35
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Like them or lump them, Global variables are a must in VB.

    In the good old days of pascal, it was possible to write a program without a single Global variable. I managed to write a scheduling program for a fire station (for my A-level project) without using a single one. This encourages good coding.


    Unfortunaley, the same is imposible with VB. Try it and see how far you get. (i estimate about nowhere), so get used to them.
    Iain, thats with an i by the way!

  36. #36
    Guest

    Question Is this all done in one form

    If so you can declare as Private in the General area...by the way use the command Option Explicit to enforce integrity. Global works for multi-form and multi class or bas projectes, where something like say Company Name can be setup in a start module.

    Then again l may just be teaching my grandmother how to suck eggs. Hey good solution Iain.

  37. #37

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Lightbulb LAST HURDLE

    Where do i call the declarations for set database, it doesn't like this??

    Option Explicit
    Dim lne$
    Dim DirFlag As Boolean
    Dim FilesCopied As FileSystemObject
    Dim DB As Database
    Dim rs As Recordset
    'set db location
    Set DB = OpenDatabase(App.Path & "\configuration.mdb")
    'Open the Contact table
    Set rs = DB.OpenRecordset("SELECT netVESPAWeb.*, ISDefine.SetPreProccessor, altCarriers.Carrier FROM (ISDefine INNER JOIN netVESPAWeb ON ISDefine.ID = netVESPAWeb.ISPreProccessorType) INNER JOIN altCarriers ON netVESPAWeb.SetCarriers = altCarriers.ID", dbOpenDynaset)

  38. #38

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    Post select all

    Is this correct for select all??


    For i = Check1.LBound To Check1.Ubound
    Check1(i).value = vbChecked
    Next i



  39. #39
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Answer to First post is on its way via E:mail.

    Answer to second post = Exactly right.
    Iain, thats with an i by the way!

  40. #40
    Guest

    Thumbs up Now that's a question no one aks

    For me only approx 30 or so questions...however generally post questions internally on our intranet which we share with a couple of other companies. Only if caren't get answer will post to this site. But...and this is a big but...have picked up ideas/solutions/techniques from reading other posts.

    Generally skim through once or twice a day to see if l can help anyone out. Didn't know about this site when l started vb, and man it would have solved some late nights and the cost of books.

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