DarkPumpkin

RandomEveryting Microsoft Access theme

Mar 19th, 2021
1,062
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'paste this into a module.
  2. 'Call the randomness from a form with "ChangeTheme (Me.Name)" in any event that you want to cause a theme change.
  3. 'You do not need to use the form name. Use it exactly as shown here.
  4. 'I recommend putting "ChangeTheme (Me.Name)" in the Form Load.
  5. 'Note that your form MUST have a header, footer, and detail!
  6. 'Although you can get rid of that requirement by remove the 4 lines at the end that start with "Frm"
  7. 'This VBA was created in Access 2016 64 bit. I do not know if it will work in other versions.
  8.  
  9.  
  10. Public Function RandomRGB(MinR As Integer, MaxR As Integer, MinG As Integer, MaxG As Integer, MinB As Integer, MaxB As Integer) As Long
  11.     'produce a random RGB value with a min and max for each r, g, and b
  12.    RandomRGB = RGB(Int((MaxR - MinR + 1) * Rnd + MinR), Int((MaxG - MinG + 1) * Rnd + MinG), Int((MaxB - MinB + 1) * Rnd + MinB))
  13. End Function
  14.  
  15. Public Function RandomFont()
  16.     'returns a random font name
  17.    Dim FontList(4) As String
  18.     FontList(0) = "Webdings"
  19.     FontList(1) = "Batangs"
  20.     FontList(2) = "Papyrus"
  21.     FontList(3) = "Arial"
  22.     FontList(4) = "Tahoma"
  23.     'Int(lowerbound + Rnd * ( upperbound – lowerbound + 1 ) )
  24.    RandomFont = FontList(Int(0 + Rnd * (4 - 0 + 1)))
  25. End Function
  26.  
  27. Public Function RandomFontSize() As Integer
  28.     'Int(lowerbound + Rnd * ( upperbound – lowerbound + 1 ) )
  29.    RandomFontSize = Int(4 + Rnd * (15 - 4 + 1))
  30. End Function
  31.  
  32.  
  33. Public Function ChangeTheme(FormName As String)
  34.     Dim ColorsNeedToBeChanged As Boolean
  35.     Dim ctlVar As Control
  36.     Dim Frm As Form
  37.     Dim MinToUseRGB As Integer
  38.     Dim MaxToUseRGB As Integer
  39.     Dim MultToUseRGB As Integer
  40.     Set Frm = Forms(FormName)
  41.     MinToUseRGB = 0
  42.     MaxToUseRGB = 10
  43.     MultToUseRGB = 25
  44.     ColorsNeedToBeChanged = False
  45.     Randomize
  46.    
  47.        
  48.     For Each ctlVar In Frm.Controls
  49.         ctlVar.Width = ctlVar.Width + Int((140 - (-140) + 1) * Rnd + (-140))
  50.         ctlVar.Height = ctlVar.Height + Int((70 - (-30) + 1) * Rnd + (-30))
  51.         ctlVar.Left = ctlVar.Left + Int((100 - (-0) + 1) * Rnd + (-0))
  52.         ctlVar.Top = ctlVar.Top + Int((100 - (-0) + 1) * Rnd + (-0))
  53.         If ctlVar.ControlType = acTextBox Or ctlVar.ControlType = acComboBox Then
  54.             ctlVar.FontName = RandomFont
  55.             ctlVar.FontSize = RandomFontSize
  56.            
  57.             ctlVar.BackColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  58.             ctlVar.ForeColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  59.             ctlVar.BorderColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  60.         End If
  61.         If ctlVar.ControlType = acLabel Then
  62.             ctlVar.FontName = RandomFont
  63.             ctlVar.FontSize = RandomFontSize
  64.            
  65.             ctlVar.ForeColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  66.         End If
  67.         If ctlVar.ControlType = acCommandButton Then
  68.             ctlVar.FontName = RandomFont
  69.             ctlVar.FontSize = RandomFontSize
  70.        
  71.             ctlVar.BackColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  72.             ctlVar.BorderColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  73.             ctlVar.ForeColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  74.             ctlVar.HoverColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  75.             ctlVar.HoverForeColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  76.             ctlVar.PressedColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  77.             ctlVar.PressedForeColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  78.             ctlVar.Gradient = Int((26 - 0 + 1) * Rnd + 0)
  79.         End If
  80.         If ctlVar.ControlType = acRectangle Then
  81.  
  82.        
  83.             ctlVar.BackColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  84.             ctlVar.BorderColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  85.         End If
  86.         If ctlVar.ControlType = acTabCtl Then
  87.             ctlVar.FontName = RandomFont
  88.             ctlVar.FontSize = RandomFontSize
  89.        
  90.             ctlVar.BackColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  91.             ctlVar.BorderColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  92.             ctlVar.ForeColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  93.             ctlVar.HoverColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  94.             ctlVar.HoverForeColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  95.             ctlVar.PressedColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  96.             ctlVar.PressedForeColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  97.         End If
  98.         If ctlVar.ControlType = acAttachment Then
  99.  
  100.             ctlVar.BackColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  101.             ctlVar.BorderColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  102.         End If
  103.     Next
  104.     Frm.FormHeader.BackColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  105.     Frm.Detail.BackColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  106.     Frm.Detail.AlternateBackColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  107.     Frm.FormFooter.BackColor = RandomRGB(MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB, MinToUseRGB, MaxToUseRGB) * MultToUseRGB
  108.     Set Frm = Nothing
  109. End Function
RAW Paste Data