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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning input to main form

Status
Not open for further replies.

FrankMars

Technical User
Dec 20, 2010
67
US
From my main form I am opening a second form, a calculator. I would like to return the completed calculation and focus from the calculator back to a textbox on the main form. I have been unsuccessful trying the DoCmd.GoToControl and Forms!,etc. Could someone offer an example?
 
How are ya FrankMars . . .

Perhaps:
Code:
[blue]   Forms![purple][B][I]MainFormName[/I][/B][/purple].SetFocus
   Forms![purple][B][I]MainFormName[/I][/B][/purple]![purple][B][I]ControlName[/I][/B][/purple].SetFocus[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
This is probably the most flexible method and best method to return values from pop up forms. Because you can call the form from unlimited locations. This way a calculator can be used anywhere.

1) On all pop up forms that I use to return values I have an OK and Cancel button. The OK sets the form to invisible, cancel closes the form.

My code to get the value is like this in the calling form
Code:
  Dim rtnValue As Variant
  rtnValue = getValueFromForm("YourPopUpFormName", "TheControlOnthePopUpName")
  If Not IsNull(rtnValue) Then
    'do something with the value
  End If
End Sub

A generic function to call a pop up and return a value
Code:
Public Function getValueFromForm(frmName As String, controlName As String) As Variant
  Dim frm As Access.Form
  DoCmd.OpenForm frmName, , , , , acDialog
  'Code stops here until the pop up form is hidden/closed
  If CurrentProject.AllForms(frmName).IsLoaded Then
    Set frm = Forms(frmName)
    getValueFromForm = frm.Controls(controlName).Value
    DoCmd.Close acForm, frmName
  End If
End Function

If you put an OK button that hides the form, when you pick OK the form hides and the code starts running again. It checks if the form is open but hidden. It reads the value from the specified control and then returns it to you.
 
FrankMars . . .

I use a similar approach as [blue]MajP[/blue] ... only I use a one liner in the calling form. However I use [blue]OpenArgs[/blue] to pass the name of the calling form and control to update. The called form then performs the update of the called form in the [blue]UnLoad[/blue] event. For the calling form its:
Code:
[blue]   DoCmd.OPenForm "[purple][B][I]CalledFormName[/I][/B][/purple]", , , , , acDialog, "[purple][B][I]CallingFormName[/I][/B][/purple];[purple][B][I]ControlToUpdateName[/I][/B][/purple]"
   [green]'code stops here
   'continue with any other code[/green][/blue]
... and in the [blue]UnLoad[/blue] event of the called form:
Code:
[blue]   Dim ary
   
   If Me.OpenArgs <> "" Then
      ary = Split(Me.OpenArgs, ";")
      
      If CurrentProject.AllForms(ary(0)).IsLoaded Then
         Forms(ary(0))(ary(1)) = Me![purple][B][I]AnswerControlName[/I][/B][/purple]
         Forms(ary(0)).SetFocus
      End If
   End If[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top