Reference Data from Dialog Box to Main Form

Posted on 2006-05-21
Last Modified: 2008-03-17
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.
Question by:Bob_Gardner
    LVL 65

    Expert Comment

    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
    LVL 58

    Accepted Solution

    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.



    Author Comment

    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.
    LVL 58

    Expert Comment

    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!

    Author Comment

    Thanks for the info. I have do so!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
    It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
    Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
    What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now