Reference Data from Dialog Box to Main Form

I have a form (frm_MainLog). When selecting one of the records to close from that form, I have a dialog box (popup, modal) that is opened and requires information to be entered in a specific format. The dialog box (frm_Input) is unbound and has one textbox field (CaseNumber). I do not want to use the inputbox method (which I have been using), as it does not permit me to use an input mask to insure that the data is entered in the specific and correct format.
I now need to move the input data from the dialog box textbox to a string variable in the code of the form (frm_MainLog). The variable is [sresponse] (where it is later concatenated with another variable, before being posted to the appropriate field in frm_MainLog)

The problem I am having is
 (1) how to reference the dialog's textbox and post the data to the main forms declared variable, then
(2) close the dialog without having to add any command buttons to the dialog. (do I close the dialog box in frm_MainLog code, or use an AfterUpdate event in the dialog box code?)
Would appreciate the help.
Who is Participating?
Hello Bob_Gardner

The standard way to do this (mimic an input box) is to have two buttons [OK] (property Default: yes) and [Cancel] (property Cancel: yes), with these event handlers:

Private Sub cmdCancel_Click()
    DoCmd.Close acForm, Me.Name
End Sub

Private Sub cmdOK_Click()
    Me.Visible = False
End Sub

The main form then uses this:

    DoCmd.OpenForm "frm_Input", WindowMode:=acDialog
    ' (code is interrupted while that form is open and visible)
    If SysCmd(acSysCmdGetObjectState, acForm, "frm_Input") Then
        ' form is only hidden, we can use it...
        Me.txtSomething = Forms!frm_Input!CaseNumber
        ' and close now!
        DoCmd.Close acForm, "frm_Input"
        ' the user pressed [Cancel], [Esc] or [x] to close the form
        ' do something else here?
    End Sub

Try it that way. It's totally intuitive. Just pressing [Enter] after typing the case number activates the [OK] button (because of the property Default: yes) and just [Esc] cancels the operation.


u can do one of two things

define a global variable in a module

then use that in both your forms

or define a public procedure in your form, then call that passing in your inputted text
this public procedure will then set the variable

this all done on the OK button, after that, u close the form DoCmd.Close

Just a thought, feedback purposes only, I wondered why u gave a C when I suggested using a unbounded box and which is what your doing now
Bob_GardnerAuthor Commented:
The answer I received from harfang was presented in such a manner that I was able to fully understand the dynamics. To say that it worked, is an understatement. I modified his suggestions in several ways, including using comboboxes in the input form to restrict, even further, the type of acceptable information.
As a result, I have INCREASED the points to 500 and graded the answer "A".
I have also, extended my apologies to rockiroads for the "C" grade that I gave, through my own ignorance, of the question that preceed this one. That apolgy is posted as a comment in the orginal question.
Thank you, Bob_Gardner, for your compliments and also for the ponts. I'm glad you liked the explanations. If you feel that way about rockiroads and your previous question, you could send a little note in http:/Community_Support/ titled "Please reopen", with only this line:

    Please reopen {http:/Q_21851601.html} to let me change the grade.

They often do it within minutes, it's really quite frequent.

Good luck with your application!
Bob_GardnerAuthor Commented:
Thanks for the info. I have do so!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.