How to call a form with a control as parameter

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an application running with a touch screen and no keyboard.

To enter numbers you touch the control and a numeric keyboard form opens and
you type the numbers you want. As you touch the numbers, they are written in
the control for that number.

I have several number fields and use the same keyboard form. Therefore I
would like to pass the control as a paramter so that I can have the keyboard
form fill in the numbers in that control.

How is that done?

Example:

Forms!form1!DataField = Forms!form1!DataField & 1

would add a "1" to the control DataField on form1 - but how do I make that
control a parameter?

Alternatively I have code based on each control that can call up the
keyboard form, and then I fill in the relevant control in dedicated code.
 
I do something similar to this for a pop-up calendar. Try this:

1. Create a property in your keyboard form, i.e.,

Private mctl As Control 'form level variable

Public Property Set ActiveControl(RHS As Control)

On Error Resume Next

Set mctl = RHS

End Property

'Refer to mctl within the form and you'll be manipulating the control

2. Create a sub to open your keyboard form and pass the control, i.e.,

'Method 1

Sub OpenKybdForm(Active As Control)

Dim frm as Form

Docmd.OpenForm "KeyBoardForm"

Set frm = Forms("KeyBoardForm")

Set frm.ActiveControl = Active

End Sub

'Alternate method

Sub OpenKybdForm()

Dim frm as Form

Docmd.OpenForm "KeyBoardForm"

Set frm = Forms("KeyBoardForm")

Set frm.ActiveControl = Screen.ActiveControl

End Sub


3. Call OpenKydbForm from whatever event is appropriate

Method 1

OpenKybdForm Me.SomeControl

'Alternate method

OpenKybdForm
 
Back
Top