• ** There has been a recent site upgrade. Please clear your browser cache to avoid issues. **
  • New forum feature - post voting and best solution

    Check out this thread for the details: https://www.access-programmers.co.uk/forums/threads/new-forum-feature-post-voting-and-best-answer.314134/

    This new feature looks great to me! :)

  • We now have 3 forum themes

    Go for the default (light) theme, Shades of Grey or Shades of Blue. I just added the Blue one.

    The thread about it is here: https://www.access-programmers.co.uk/forums/threads/new-forum-theme-shades-of-blue.314136/

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

Mike Krailo

Member
Local time
Today, 14:28
Joined
Mar 28, 2020
Messages
126
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

error reading drive A:
Local time
Tomorrow, 02:28
Joined
May 7, 2009
Messages
10,588
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

Member
Local time
Today, 14:28
Joined
Mar 28, 2020
Messages
126
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, 11:28
Joined
Oct 29, 2018
Messages
12,536
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

Member
Local time
Today, 14:28
Joined
Mar 28, 2020
Messages
126
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

error reading drive A:
Local time
Tomorrow, 02:28
Joined
May 7, 2009
Messages
10,588
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

Member
Local time
Today, 14:28
Joined
Mar 28, 2020
Messages
126
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