Results 1 to 5 of 5

Thread: Set Form

  1. #1
    Join Date
    Dec 2002
    Posts
    97

    Angry Unanswered: Set Form

    Okay...I'm at a lost.

    I've done this many times before and now I get an error. Here's my code.

    Private Sub Command0_Click()
    Dim frm As Form

    Set frm = Forms!frmFacEmployee

    Debug.Print frm.Name


    End Sub

    When I try to run this code I get an error that Access can't find the form. I've checked the spelling going so far as to copy directly from the form and I've compacted and repaired the Db as well as compiling the code.

    What the heck?!

    Thanks for any help.

    Chris

  2. #2
    Join Date
    Feb 2004
    Location
    Canada
    Posts
    133
    I'm guessing that the form is not open. It needs to be open when you try to refer to it.

  3. #3
    Join Date
    Jan 2005
    Posts
    73
    hmm... Maybe u should try this

    Dim frm as New Form

    try to New the Form, hope it helps

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    What is the ultimate purpose of your code? What are you actually trying to accomplish?

    Code:
    Private Sub Command0_Click()
       Dim frm As Form
       DoCmd.OpenForm "frmFacEmployee", , , , , acHidden
       Set frm = Forms!frmFacEmployee
       MsgBox frm.Name
       ' Whatever else.....
     
       DoCmd.Close acForm, "frmFacEmployee"
    End Sub

  5. #5
    Join Date
    Dec 2002
    Posts
    97

    Duh....

    And this is why you should take breaks....

    In my original code I had placed the check to see if the form was open after the set frm command.

    Long days....too much code.

    Thanks for the second pair(s) of eyes.

    Here's what it should look like.....

    Dim varID As String, rs As Object, frm As Form

    If CurrentProject.AllForms("frmFacEmployee").IsLoaded = True Then
    Set frm = Forms!frmFacEmployee

    Forms!frmFacEmployee.Visible = True
    varID = IIf(IsNull(frm!ID_Facility) = True, "Blank", frm!ID_Facility)

    If varID = "Blank" Then

    Exit Sub
    End If
    Else

    Something else.......

    End If



    Thanks again.

    -C
    Last edited by Mr_Yabbo; 03-09-05 at 12:16.

Posting Permissions

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