Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2014
    Posts
    3

    Unanswered: Open additional Forms from a Main Form

    Good morning,

    This is my first time using Access. I am using Access 2010. I have a main form that has a combo box that list all the forms. The code I used to build the combo box appears to be working (combo box is loaded with all the form names).

    Combo box load code:
    Code:
    SELECT MSysObjects.Name FROM MsysObjects WHERE (Left$([Name],1)<>"~") And (Left$([Name],3)="Frm") And (MSysObjects.Type)=-32768 ORDER BY MSysObjects.Name;

    My goal is to select a form from the combo box and open the form with a common button. Some of the forms are for data manipulation and for printing multiple reports. When I click on the button to select the new form nothing happens. Below is the code for my Open Form Button. Any suggestions would be greatly appreciated! Thank you!

    Open Form Button Code:
    Code:
    Private Sub OpenForm_Click()
       If Not IsNull(ComboForms) And ComboForms <> "" Then
         DoCmd.OpenForm ComboForms, AcFormView  'AcFormOpenDataMode
       Else
         MsgBox ("You Must First Select a Form to Open!")
         ComboForms.SetFocus
       End If
       ComboForms = ""
    End Sub
    Last edited by Missinglinq; 02-15-14 at 11:38. Reason: Adding code tags

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Not sure where the problem is, however this works:
    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub OpenForm_Click()
    
        With Me.ComboForms
            If Nz(.Value, "") <> "" Then
                DoCmd.OpenForm .Value, acNormal ' was AcFormView
            Else
                MsgBox ("You Must First Select a Form to Open!")
                .SetFocus
            End If
            .Value = ""
        End With
        
    End Sub
    Have a nice day!

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    The problem with the OP's code is that AcFormView is the name for type of Constant that particular parameter/argument takes, it is not a valid value for it! Valid values would be
    • acDesign
    • acFormDS
    • acFormPivotChart
    • acFormPivotTable
    • acLayout
    • acNormal
    • acPreview
    with acNormal being Sinndho's choice. His suggestion of adding Option Explicit, at the top of your Form's code module, is also an excellent one!

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    many mentions on the web of strange results when using isnull(combo)
    combo.listindex is -1 when nothing is selected.
    so try:
    Code:
    if combo.listindex = -1 then
    msgbox "select something"
    else
    docmd.openform..........
    endif
    izy
    currently using SS 2008R2

  5. #5
    Join Date
    Feb 2014
    Posts
    3
    Izy,

    Thank you for your time and reply!

    Congamond

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

  7. #7
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Quote Originally Posted by izyrider View Post
    many mentions on the web of strange results when using isnull(combo)
    izy,

    Can you post references about this? I tried to google for it but could not find anything.
    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
  •