Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to use Variables? (A2k (9.0.3821) SR-1)

    How to use Variables?

    A2k (9.0.3821) SR-1

    How do I reference the form name frm_TOC_BP_ACD in the last two statements using a variable?

    Thanks, John Graves

    Dim strFormName As String
    Dim strSQL As String

    strFormName = "frm_TOC_BP_ACD"
    strSQL = "SELECT * FROM " & mstrTableName & " WHERE " & mstrIDName _
    & " = " & Me!sub1.Form!lngID

    DoCmd.OpenForm strFormName, WindowMode:=acHidden
    Forms!frm_TOC_BP_ACD.RecordSource = strSQL
    Forms!frm_TOC_BP_ACD.Visible = True

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: How to use Variables? (A2k (9.0.3821) SR-1)

    You could use syntax like this:<pre> Dim frm As Form_frm_TOC_BP_ACD
    DoCmd.OpenForm "frm_TOC_BP_ACD", , , , , acHidden
    Set frm = Forms![frm_TOC_BP_ACD]

    With frm
    .RecordSource = strSQL
    .Visible = True
    End With

    Set frm = Nothing </pre>

    You use an object variable (frm), specify the form to reference (Form_NameOfForm), open form, then set object variable to instance of form you just opened. You can then use frm & dot operator to reference the form's properties and methods. Functions/procedures declared as Public will be listed as form methods when you type the dot after "frm". Public variables will be listed as properties. NOTE: I've never had much luck using WindowMode = acHidden when opening form; it still opens momentarily, resulting in an annoying flash on screen....
    HTH

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: How to use Variables? (A2k (9.0.3821) SR-1)

    I've never seen that problem using acHidden. I set the frm variable to Form, not to an instance of a specific form class unless I'm using the New keyword, and maybe that makes a difference. This works for me:

    Dim frm As Form
    DoCmd.OpenForm "frm_TOC_BP_ACD",,,,,acHidden
    Set frm = Forms!frm_TOC_BP_ACD
    Charlotte

  4. #4
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to use Variables? (A2k (9.0.3821) SR-1)

    Hi All

    I was trying to eliminate hard coding the form name

    This worked for me.

    Thanks

    strTableName = Form_frm_Search_BP_MainForm.mstrTableName
    strIDName = Form_frm_Search_BP_MainForm.mstrIDName
    strFormName = Form_frm_Search_BP_MainForm.mstrFormName
    strSQL = "SELECT * FROM " & strTableName & " WHERE " & strIDName & " = " & Me!lngID
    DoCmd.OpenForm strFormName, WindowMode:=acHidden
    Forms(strFormName).RecordSource = strSQL
    Forms(strFormName).Visible = True

  5. #5
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Open Form in Stealth Mode

    Thanx, I tried your suggestion. I was still having problems opening form in hidden mode, whether declaring variable as generic Form object or as specific form -- the form would not stay hidden. After some testing found the problem was the form's On Load event, which included a DoCmd.Maximize statement. A window that is maximized obviously doesn't stay hidden very long (obvious to me now, anyway!). So for anyone opening a form in stealth mode, recommend avoiding any Maximize or similar statements till you make form visible.

Posting Permissions

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