0

I need to create a small MS Access touchscreen POS (point of sale) application.

If someone has a rudimentary touchscreen MS Access template they can point me to, so that I can learn from it, that would help tremendously.

I have been able to find code for a touchscreen keyboard, which I will use.

The person using the interface needs to click on the name of a person as part of the POS process. The people change often, so I need to update the list often.

I am looking for a way to use VBA to create the onscreen buttons dynamically based on a list of people I update in a separate form.

The form will naturally be full-screen, and will never have more than 50 buttons on the screen representing the list of people. Only a few (less than 5) other controls will be present on this form, so the buttons representing the list of people needs to be constrained to an area on the form. The form must read the list of people, then create fixed sized, large square buttons automatically and be arranged alphabetically from left to right.

Thank you.

wickyd
  • 277
  • 1
  • 11
  • Rather than buttons I would consider using a list box. Access will take care of all the updating and it will be able to scroll rather than have to worry about formmating all the buttons to fit. I con't think it is possible to add and remove buttons with code, rather you can change their visibility and text and then have them interact with a lookup table of some sort. – Evan Jul 16 '15 at 15:00
  • Thanks for the suggestion Evan, but I would prefer to use buttons. – wickyd Jul 16 '15 at 16:18

1 Answers1

0

Something like this should work for you then. You'll need to make the max amount of buttons you will need on the form and space them and make an OnClick event for each like the one here for Command0. Then when the form is opened the array is initialized and all the buttons are captioned and made visible up to the amount of records in the table.

When each button is clicked it calls the HandleClick Sub to interact with the data as you need.

I made the recordset global so that it is only filled once and avoid weird data issues if the customers table is updated while this form is in use.

Dim Buttons(1 To 4) As Control
Dim rst As DAO.Recordset

Private Sub Command0_Click()
    HandleClick (1) 'number that corresponds to this button in the array as
                    'initialized in the Form_Load sub, hard coded
End Sub

Private Sub Form_Load()
    'initialize the buttons
    Buttons(1) = Me.Command0
    Buttons(2) = Me.Command1
    Buttons(3) = Me.Command2
    Buttons(4) = Me.Command3

    Dim sql As String
    sql = "SELECT * FROM tblCustomers"
    Set rst = CurrentDb.OpenRecordset(sql)

    FillButtons
End Sub


Sub FillButtons()
    If (rst.EOF And rst.BOF) = False Then
        rst.MoveFirst

        Dim itr As Integer
        Do
            Buttons(itr).Caption = rst("CustomerName")
            Buttons(itr).Visible = True
            rst.MoveNext
        Loop While rst.EOF = False
    End If
End Sub

Sub HandleClick(CustomerNumber As Integer)
    'Here is where you do what you intended with the button using
    'customer number to know which record was clicked
End Sub

It's a messy approach but it should work.

Evan
  • 600
  • 2
  • 7
  • 34