Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Location
    Gatineau, Quebec Canada
    Posts
    147
    Provided Answers: 1

    Unanswered: Calling a Forum Control

    In "frmTransact", I wish to use the name of the calling form (frmMain):

    in the first form ("frmMain"), I call the second form ('frmTransact") thus
    docmd.openform.....
    docmd.close "frmMain"

    In the second form("frmTransact"):

    private aFormName as string

    Private Sub Form_Open (Cancel as integer)
    Dim myID as integer

    aFormName = Screen.ActiveForm.name

    myID = [Forms]![aFormName]!txtID.value ' (txtID is a control in the first form)

    This throws an error .."cannot reference aFormName". However, "aFormName" contains the actual name of the first form ("frmMain"); it appears if you add " msgbox aFormName" to the FormOpen event of the second form.

    Why do I get this error? If I use instead

    myID = [Forms]![frmMain]!txtID.value

    it works fine. Obviously something I don't understand about controls.

    J. Smith
    Aylmer, Quebec
    Last edited by praxis1949; 01-27-14 at 17:39. Reason: Poor proof reading

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    I would try:
    Code:
        Dim frm As Form
        Dim myID as integer
    
        Set frm = Screen.ActiveForm
        myID = frm.Controls("txtID").Value
    or directly:
    Code:
        Dim myID as integer
    
        myID = Screen.ActiveForm.Controls("txtID").Value
    Have a nice day!

  3. #3
    Join Date
    Mar 2009
    Location
    Gatineau, Quebec Canada
    Posts
    147
    Provided Answers: 1
    Ah, that makes sense. I got into more advanced programming in my 50s, and had (and have) a bit of trouble grasping some concepts (especially manipulating controls).

    Thanks again,

    John S

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •