Disable form with a checkbox

ezpc

Registered User.
Local time
Today, 11:20
Joined
Sep 7, 2000
Messages
19
I want a user to be able to turn off an informational form with a checkbox. I added this code to the On Open event of the form.

If Me.HideIntro = True Then
DoCmd.Close
End If

It didn't work though. The check box doesn't stay checked and the form continues to open after it has been checked.

Any help would be appreciated.
 
Checkbox form in Northwin

Rich,

Yes, I have looked at the one in Northwind. I got a little confused though because that one is on the startup form and I do want my existing startup form to stay the same(it has a verification of backend location routine).
 
The method that northwind uses a database property. The code to define a property (as copied from northwind) is:
Code:
        Dim db As DAO.Database
        Dim prop As DAO.Property
        Set db = CurrentDb()
        Set prop = db.CreateProperty("StartupForm", dbText, "Startup")
        db.Properties.Append prop

Northwind runs this function in the form's close event:
Code:
Function HideStartupForm()
On Error GoTo HideStartupForm_Err
' Uses the value of HideStartupForm check box to determine the setting for
' StartupForm property of database. (The setting is displayed in Display Form
' box in Startup dialog box).
' Used in OnClose property of Startup form.
        If Forms!Startup!HideStartupForm Then
        ' HideStartupForm check box is checked, so set StartupForm property to Main SwitchBoard.
            CurrentDb().Properties("StartupForm") = "Main SwitchBoard"
        Else
            ' HideStartupForm check box is cleared, so set StartupForm property to Startup.
            CurrentDb().Properties("StartupForm") = "Startup"
        End If
    
        Exit Function
        
HideStartupForm_Err:
    Const conPropertyNotFound = 3270
    If Err = conPropertyNotFound Then
        Dim db As DAO.Database
        Dim prop As DAO.Property
        Set db = CurrentDb()
        Set prop = db.CreateProperty("StartupForm", dbText, "Startup")
        db.Properties.Append prop
        Resume Next
    End If
End Function

And this function in the form's open event:
Code:
Function OpenStartup() As Boolean
' Displays Startup form only if database is not a design master or replica.
' Used in OnOpen property of Startup form.
On Error GoTo OpenStartup_Err
    If IsItAReplica() Then
        ' This database is a design master or replica, so close Startup form
        ' before it is displayed.
         DoCmd.Close
    Else
        ' This database is not a design master or replica, so display Startup form.
        ' Set the value of HideStartupForm check box using the value of
        ' StartupForm property of database (as set in code or in the
        ' Display Form/Page box in Startup dialog box).
        If (CurrentDb().Properties("StartupForm") = "Startup" Or _
            CurrentDb().Properties("StartupForm") = "Form.Startup") Then
            ' StartupForm property is set to Startup, so clear HideStartupForm
            ' check box.
            Forms!Startup!HideStartupForm = False
        Else
            ' StartupForm property is not set to Startup, so check HideStartupForm
            ' checkbox.
            Forms!Startup!HideStartupForm = True
        End If
    End If
   
OpenStartup_Exit:
    Exit Function
        
OpenStartup_Err:
    Const conPropertyNotFound = 3270
    If Err = conPropertyNotFound Then
        Forms!Startup!HideStartupForm = True
        Resume OpenStartup_Exit
    End If
End Function

You could use a table rather than defining a database property if you prefer.
 
Checkbox to disable form

Thank you so much! I've got it working fine now.
 

Users who are viewing this thread

Back
Top Bottom