Reference to all the form in the data base

  • Thread starter Thread starter 123
  • Start date Start date
1

123

Thank you

Reference to all the form in the data base

Is there any way to Reference to all the form in the data base using code..
because I need to apply changes to all forms in one action?
 
123 said:
Thank you

Reference to all the form in the data base

Is there any way to Reference to all the form in the data base using
code.. because I need to apply changes to all forms in one action?

Here's a quickie routine I wrote in answer to another question a while
back, to change the font of all controls on all forms in the database.
Maybe you can modify it to suit your needs, or if you can't, at least it
shows how to go about modifying every form in the database.

'----- start of code -----
Private Sub cmdChangeFont_Click()

On Error GoTo Err_cmdChangeFont_Click

Dim aoForm As AccessObject
Dim frm As Form
Dim ctl As Control
Dim strFont As String

strFont = Me.cboFont & vbNullString
If Len(strFont) = 0 Then
MsgBox "Choose a font first!", , "No Font Selected"
Exit Sub
End If

If MsgBox( _
"Are you sure you want to change the font on all " & _
"controls on all forms in this whole gosh-darn database?", _
vbYesNo + vbExclamation + vbDefaultButton2, _
"You'd Better Be Sure!") _
= vbNo _
Then
Exit Sub
End If

For Each aoForm In CurrentProject.AllForms

If aoForm.Name <> Me.Name Then
SysCmd acSysCmdSetStatus, _
"Processing form " & aoForm.Name & " ..."
Application.Echo False

DoCmd.OpenForm aoForm.Name, acDesign
Set frm = Forms(aoForm.Name)

For Each ctl In frm.Controls
ctl.FontName = strFont
Next ctl

Set frm = Nothing
DoCmd.Close acForm, aoForm.Name, acSaveYes

Application.Echo True
End If

Next aoForm


Exit_cmdChangeFont_Click:
Application.Echo True
SysCmd acSysCmdClearStatus
Exit Sub

Err_cmdChangeFont_Click:
Select Case Err.Number
Case 438
Resume Next
Case Else
Application.Echo True
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume Exit_cmdChangeFont_Click
End Select
End Sub
'----- end of code -----
 
Back
Top