Results 1 to 7 of 7
  1. #1
    epardo87 is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Dec 2016
    Posts
    101

    shortcut for Repetitive button coding?

    Hello there,

    I have a point of sale form to be used on touchscreen devices, for which I have a button made for each product. I have 105 buttons split into tabs of about 10 buttons per tab according to the kind of product. the thing is, I've already created a custom function that contains the formula for each button, but I'm having all this repetitive coding that I believe there might be a way to do this with a loop or something perhaps, I'm no programmer and it's been years since the last time I used access but I've been finding my way to write most of this form with VBA.
    the custom function is called "Buttons" and the only thing that change is the product's part number in the name and the code... is there something you would suggest?

    thanks for your time in advance

    Code:
    Private Sub PN2001Btn_Click()
        Buttons 2001
    End Sub
    Private Sub PN2003Btn_Click()
        Buttons 2003
    End Sub
    Private Sub PN2004Btn_Click()
        Buttons 2004
    End Sub
    Private Sub PN2005Btn_Click()
        Buttons 2005
    End Sub
    
    ...
    
    Private Sub PN****Btn_Click()
        Buttons ****
    End Sub


  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Not sure what you're after.
    Perhaps it is something like this: you can create a function in a standard module that accepts a parameter for the Screen.ActiveControl.somePropertyHere, where the last part is the name, tag, caption or other useful property of the button that was clicked. Then in design view you can select a whole whack of buttons (what is a whack anyway?) and set the On Click event property to the name of that function. When clicked, those buttons will run said function. In that function you could use a Select Case block to determine what to do. However, you will have 105 Case statements in that block - something that I've never done to that extent. Each one of those case statements would do something different if need be. I say that because I don't know what those 105 calls to "Button" do.

    There are probably other solutions; one perhaps being to use WithEvents. However, I must confess to never having used that method, and FWIK it would require you to declare 105 variables (one for each button) but don't quote me on that. Perhaps someone knows how to write a class for all command buttons that can distinguish between the 105 of concern and ignore ones that do things like open forms, but that's not me.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Maybe with some fancy custom class coding.

    Otherwise, what you have is about as compact as you can get.
    Last edited by June7; 02-14-2024 at 09:51 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    I'm a little wary of the need for a button per part number as a structure?
    What happens when product 106 arrives? You need to add another button and code to accommodate it?

    This sounds like a data structure design issue rather than a problem with repetitive buttons, unless I'm missing something obvious?

    The obtuse answer is that each button would be in a repeated subform, and that the product code was allocated in code on form opening?
    The code could then be based on the product code not the button number?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    This class will handle any number of buttons. This example has 42 buttons with no code behind them.
    Attached Files Attached Files
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #6
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Another version which is more like a point of sale
    Attached Files Attached Files
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  7. #7
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,474
    Instead of all the buttons, could you just have a combo box of Part numbers and code behind it to do what you need for the specific Part?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Coding problem with Exit button
    By NightWalker in forum Programming
    Replies: 11
    Last Post: 06-06-2016, 01:05 PM
  2. Email command button coding needed
    By bradp1979 in forum Forms
    Replies: 3
    Last Post: 10-09-2015, 03:30 PM
  3. Newb VBA coding help cmd button that copies records
    By illicited in forum Programming
    Replies: 3
    Last Post: 05-02-2013, 04:27 PM
  4. Button Coding
    By yamie in forum Programming
    Replies: 3
    Last Post: 02-22-2010, 10:45 AM
  5. Adding VB code on a embedded coding for a button
    By cwwaicw311 in forum Programming
    Replies: 1
    Last Post: 02-20-2010, 12:25 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums