Solved Set form properties on Load with a function (1 Viewer)

Mike Krailo

Well-known member
Local time
Today, 07:29
Joined
Mar 28, 2020
Messages
1,030
I have tried to set some form properties using the code below in on Load, on Open, on Activate. The very first form that loads uses this function and it has no error, but the second form that is called with this function has error runtime 2136 on line 50 "To set this property, open the form or report in Design view." The function works fine when any form is already visibly loaded on the screen. Is there an event that will accommodate this function right after the form loads?

Code:
Function ProtectForm(FrmName As String, Protect As Boolean)
         Dim frm As Form
10       Set frm = Forms(FrmName)
20       With frm
30          If Protect = True Then
40             .ShortcutMenu = False
50             .BorderStyle = 3  'Dialog
60             .CloseButton = False
70             .MinMaxButtons = 0  'None
80          Else
90             .ShortcutMenu = True
100            .BorderStyle = 2  'Sizable
110            .CloseButton = True
120            .MinMaxButtons = 3  'Both Enabled
130         End If
140      End With
End Function
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:29
Joined
May 7, 2009
Messages
19,169
a maybe wrong but the form must be open in design view (you can hide it) first before applying those properties.
after applying, save the form and re-open in Normal mode.
 

Mike Krailo

Well-known member
Local time
Today, 07:29
Joined
Mar 28, 2020
Messages
1,030
I'm begining to see a better way to do this differently than I originally planned. What I'm trying to really do is run a function in the immediate window that will run through a list of forms to set those properties on and then set them back when I'm done working on them.

So maybe a DevMode function that opens all the forms in a list in design view and then close all the forms again saving those properties. I have the list of forms in a table called FormList.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:29
Joined
Oct 29, 2018
Messages
21,357
I'm begining to see a better way to do this differently than I originally planned. What I'm trying to really do is run a function in the immediate window that will run through a list of forms to set those properties on and then set them back when I'm done working on them.

So maybe a DevMode function that opens all the forms in a list in design view and then close all the forms again saving those properties. I have the list of forms in a table called FormList.
That sounds like a good plan. Let us know how it goes.
 

Mike Krailo

Well-known member
Local time
Today, 07:29
Joined
Mar 28, 2020
Messages
1,030
Here's what I came up with. Does anyone know a more efficent way to walk through the recordset than the way I did it here. It seems clunky to me. It does work though.
Code:
Function DevMode(OnOff As Boolean)
   ' Open all forms in the FormList table in design view and set some properties

   Dim FormName As String
   Dim Pass As Integer
   Dim db As DAO.Database
   Dim rst As DAO.Recordset
  
   Set db = CurrentDb
   Set rst = db.OpenRecordset("FormList")
   Pass = 1
   Do
      If Pass = 1 Then
         rst.MoveFirst
         Pass = Pass + 1
      Else
         If Not rst.EOF Then
            rst.MoveNext
         Else
            Exit Do
         End If
      End If
      If rst.EOF Then Exit Do
      FormName = rst!FormName
      DoCmd.OpenForm FormName, acDesign
      ProtectForm FormName, Not OnOff
      DoCmd.RunCommand acCmdSave
      DoCmd.Close acForm, FormName
   Loop
   rst.Close
End Function
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:29
Joined
May 7, 2009
Messages
19,169
Code:
Function DevMode(OnOff As Boolean)
    ' Open all forms in the FormList table in design view and set some properties

    Dim FormName As String
    Dim db As DAO.Database
    Dim rst As DAO.Recordset

    Set db = CurrentDb
    Set rst = db.OpenRecordset("FormList")
 
    With rst
        If Not (.BOF And .EOF) Then
            .MoveFirst
        End If
        Do Until .EOF
            FormName = rst!FormName
            DoCmd.OpenForm FormName, acDesign
            ProtectForm FormName, Not OnOff
            DoCmd.Close acForm, FormName, acSaveYes
            .MoveNext
        Loop
        .Close
    End With
    Set rst = Nothing
    Set db = Nothing
End Function
 

Mike Krailo

Well-known member
Local time
Today, 07:29
Joined
Mar 28, 2020
Messages
1,030
Thanks Arnelgp, there is always another way to get the job done and I like your way better than mine.
 
Last edited:

Users who are viewing this thread

Top Bottom