Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing value of Keyboard form to calling form

Status
Not open for further replies.

ojasg

Technical User
Mar 19, 2010
30
DE
I have a Keyboard form for touchscreen application. I store the value of what the user types in txtPassingValue.

This form will be invoked each time the user clicks on any field requiring a keyboard entry on other forms. Once the keyboard form opens, the user will type in what they need to and on clicking "Done", the txtPassingValue should be passed on the control on the previous form that called for this entry.

I am unable to figure out how to refrence back to the control that called the Keyboard form.

Any help would be very much appreciated!

Thank You!
 
Have a look at the Screen.ActiveControl and Screen.PreviousControl properties.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Is your keyboard form open as dialog? Makes a differences on how to approach it. If not dialog there are more options.
 
So assume you have a non popup/dialog form called "frmReturn"
The code on that form would be
Code:
Private mCallingControl As Access.Control
Public Property Get CallingControl() As Access.Control
  Set CallingControl = mCallingControl
End Property
Public Property Set CallingControl(ByVal ctrl As Access.Control)
  Set mCallingControl = ctrl
End Property
Private Sub cmdOk_Click()
 On Error GoTo errLbl
 If Not Me.CallingControl Is Nothing Then
   Me.CallingControl.Value = Me.txtBxOutPut
 End If
 DoCmd.Close acForm, Me.Name
 Exit Sub
errLbl:
 MsgBox Err.Number & " " & Err.Description & " When trying to save to return value"
 DoCmd.Close acForm, Me.Name
End Sub
with an ok and cancel button
then you could have a function in a module
Code:
Public Sub GetValueFromForm(ctrl As Access.Control)
  Dim frm As Form_frmReturn
  DoCmd.OpenForm "frmReturn"
  Set frm = Forms("frmReturn")
  Set frm.CallingControl = ctrl
End Sub
Then you could called it from anywhere like
Code:
Private Sub Command11_Click()
 GetValueFromForm Me.PartNo
End Sub
 
If it is dialog this is how I do it. On the popup/dialog form have an OK and Cancel button. Cancel just closes the form. OK hides the form (me.visible = false).
Then put this in a standard module
Code:
Public Function getValueFromPopUp(formName As String, PopUpControlName As String) As Variant
  'FormName: Name of the popup form
  'PopupControlName: Name of the control on the pop up/dialog that you want the value
  Dim frm As Access.Form
  DoCmd.OpenForm formName, , , , acFormEdit, acDialog
  'wait until form is closed or hidden
  'The popup needs an OK button that hides the popup(me.visible = false), and a Cancel button that just closes it
  If CurrentProject.AllForms(formName).IsLoaded Then
    Set frm = Forms(formName)
    getValueFromPopUp = frm.Controls(PopUpControlName).Value
    DoCmd.Close acForm, formName
  End If
End Function
Then you can use the above code something like this
Code:
Private Sub Command5_Click()
  Dim rtn As Variant
  rtn = getValueFromPopUp("frmPopUp", "cmboOne")
  If Not Trim(rtn & " ") = "" Then
    CompanyName = rtn
  End If
 
Thanks to everyone for their inputs and prompt replies.
This is how I was able to resolve my issue.

On my "calling form" when a field that needs a numeric entry get's focus .. I use the following code -->

Private Sub Flow_GotFocus()

DoCmd.OpenForm "frmNumPad"

End Sub

Now the focus is on the frmNumPad (Called Form) which has the number keys. I type in the number I want and store the string in txtPassValue. On clicking the button "Done", I pass the value in txtPassValue field to a "Global Variable" that I declared in my module, called PassValue. I use the following code -->

Private Sub cmdDone_Click()

PassValue = txtPassValue.Value

DoCmd.Close

End Sub

Now my original form (Calling Form) that called for the frmNumPad is in focus again. I finally extract the value from the global variable PassValue and put it in the filed that invoked the form frmNumPad, by using the "OnLostFocus" event, using the following code -->

Private Sub Flow_LostFocus()

Flow.Value = PassValue

End Sub

So this code set of three gives me the ability to pass values between the called and calling form easily. I understand it's not the most correct approch, but it's easy and required less complicated coding.

Hopefully this helps someone else too!

Agan, thank you to everyone who replied.. I have learned a lot from this forum and owe a lot to you all.
 
So it looks like the answer to MayP's question: "Is your keyboard form open as dialog?" is No... Right?
When you see your frmNumPad, can you still click on "calling form"?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
>I have a Keyboard form

Presumably the built-in accessibility keyboard is not suitable?
 
Yes the built-in keyboard is too small. I build these applications for use on toughbooks, used in very demanding conditions. So the buttons have to be large. I even use my own calendar form and can't use the in built date picker.

I actually found an easier way to pass the values.. but the concept is same.. Hide the calling form; display the called form and enter values there and pass them to the hidden form. I technically don't even hide the form; I just use a "White Rectangle" and control it's visibility. So it looks like the calling form has disappeared but in relaity it is only covered with a white box.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top