Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2007
    Posts
    16

    Unanswered: Array of command buttons

    Hi all,

    I am creating a small ordering system application which will work with a touch screen.
    the problem that i have created 2 tables
    1 called departments and the other called products

    then i have say 10 command buttons on a form and when the form is loaded the command button captions are loaded from the table so cmd1 will become say pizza cmd2 will becomes burgers etc

    When the user clicks a department button then what ever is in the department category of the products table is loaded up and the product command buttons captions are loaded with the product name and when the product button is clicked the product name and price is picked up from the table and droped into a subform

    i have created something similar in vb using an array of command buttons but this doesnt work for ms access any help on this would be much appreciated

    I have attached a db which does do some of the process and can give you bit of an indication.

    thanks in in advance.
    Attached Files Attached Files

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I've had a similar issue where vb nicely gives you an array of command buttons to utilize and you program one procedure for clicking a button in the array.

    (thanks for the sample to see what you have done.) You might want to consider an Option group control of buttons (3rd one in the toolbox) in MSAccess which is probably easier to control regarding looping through and renaming the caption (or simply making a whole Option group of buttons visible/invisible with me.MyOptionGroupControlName.visible = true or me.MyOptionGroupControlName.visible = false) plus the user selects one button in the group and you don't have to program each button. This is the same type of thing where you click on one "group" and then can utilize a select case statement to determine what "number" in that group is selected without having to code each button separately. When a button that is in the option group is clicked (onClick or AfterUpdate for the Option group control), you can get the number associated with that button when clicked with: me!MyOptionGroupControlName.
    Ex:
    Private Sub MyOptionGroupControlName_Click()
    Select Case me!MyOptionGroupControlName
    Case 1
    'Do something
    Case 2
    'Do something else
    End Select

    End Sub

    The Option group wizard does a very nice job of configuring the Option group control for you.

    Otherwise, each button/caption field would need an OnClick event but you can then pass the number part of the field name to a public function with a parameter to do the work. For example, you might have a function and utilize your lookup table:

    Function setBackText(cmdButtonNum as integer, buttCaption as string)
    'do your lookup in the table here.
    tblLookupValue = dlookup("[SomeText]","[txtTable]","[TextCaption = ' " & buttCaption & " ' ")
    dim varField as variant
    varField = "cmdFieldName" & cmdButtonNum
    me.varField.caption = tblLookupValue
    end Function

    Note: The syntax on this may not be totally correct as I'm doing it from memory but you get the idea. You would utilize a table as a lookup source to control what caption get's displayed on the field or what other events run. You can set up a row of buttons such as cmdFieldName1 and cmdFieldName2, cmdFieldName3, etc.. Then you utilize the caption or the number part of the button name in the OnClick event to pass to a function to then re-caption the field or run another event.

    Something like this but you'd have to work out the flow and how you'd want to construct it. Again, it's usually easier to use an Option Group control.
    Last edited by pkstormy; 11-16-07 at 19:15.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Nov 2007
    Posts
    16

    Hi

    Thanks Pkstormy for the reply,

    The option group would i have to draw the group out and then place all the buttons in? I do kind of get you and am going to give it a try over the weekend, you said that you had a similar problem did you mananage to work it out, also would it be possible if i can get some sort of workable example as am tryin to get into the programming theme but with very little knoweldge.

    Thanks

    Regards
    Neemo

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Regarding MSAccess being able to actually have code similar to vb where you put in one procedure to handle an array of buttons clicked, I used the Option group control. It does basically the same thing. When you walk through the wizard on the Option Group, you can enter the captions for each button and then select the circle, checkbox, or button view. After you select the button, the wizard will then create the buttons, you can define a default button, and you can add new numbers and buttons to the option group after the wizard is done. You should really try the wizard on the Option group as things will make sense once you've done it. It would probably be more difficult to understand the option group unless you've walked through the wizard. Otherwise I can try to come up with an example over the next few days.

    Keep in mind that you can't do arrays with MSAccess buttons like you do with vb buttons (unless maybe you utilize the tag method) but without the option group, you'll still need to code in each onClick for each button. You'll come to favor the option group method (it's actually easier once you've done a few of them.) The more difficult route is creating a function and calling that function on every OnClick event for each button without an option group. There is a rather neat method in the code bank where you can do a highlight over effect on each button (http://www.dbforums.com/showpost.php...0&postcount=57) Nothing to do with the option group but it is kind of neat. You can probably find some other good examples in the code bank but I can't think of any option group examples offhand (but checkout some of the other examples).
    Last edited by pkstormy; 11-16-07 at 21:36.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Nov 2007
    Posts
    16
    Hi PKstormy

    Thanks for the reply again, i think i get what you mean now with the option group, i didnt know how to create it but with the wizard i understand what you mean by it now, but the only thing is they come as toggle buttons which i think would work fine only prob is that would the products be command buttons or how would i get to the products section when a button is clicked also would this be suitable for a touch screen purpose?

    I have managed to create something similar with using subforms which works the only thing is i cant place items or the department side by side but rather straight down the only prob there is am trying to show only 10 records when loaded and when the next button is clicked a further 10 appear i ahev posted that on here so i dotn know which one would be best right now.

    Thanks again

    Regards

    Neemo

  6. #6
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Yes the option group is a toggle. I personally like this but I think it's more of a preference thing. Not sure how it might work on a touch screen but I'm guessing it would work the same as a button. You might want to think about populating the sourceobject of the subform to show products when the products button/number would be selected in the option group (ex:

    Select Case me!MyOptionGroupField
    Case 1
    me.MySubformName.SourceObject = "SubformProducts"
    ...

    You can also nicely show another option group if a certain button/number is clicked:

    Select Case me!MyOptionGroupField
    Case 1
    me.myoptiongroupfield.visible = false
    me.my2ndoptiongroupfield.visible = true
    ...
    ..
    I looked at your post on the 10 records showing and thought about it. Offhand the only thing I could think of would be possibly store a number field in the table which designates the "page" (i.e. first 10 records would equal 1), then have an unbound field on the Main form which is a "counter" type field telling it what page to show. Your query for the subform would then show all the records where the PageField = Forms!MainForm!PageNumberFld. You'd have to populate the PageField on the subform and can set the default value of this field =Forms!MainForm!PageNumberFld....testing to see if adding a new record to the count() for that set of records > 10. If it is, increase PageNumberFld and then add the new record.

    I'll try and come up with something over the next few days to show you what I mean and envision with the option group.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  7. #7
    Join Date
    Nov 2007
    Posts
    16
    Hi,

    Thanks Pkstormy for the reply, i think i kinda get you on it but i think am gooing to have to give it a try tomorrow morning, i would really appreciate it if you can get a example for me regarding this problem as i am tryin to do this for my cuz and he needs it doing pretty urgent. I can send you the subform one which i have done if you like.

    thanks again

    Regards
    Neemo

  8. #8
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Here's a sample regarding the records showing 10 per page. This is just one way to do it.
    Attached Files Attached Files
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

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