Re: Form instance using variable for name
- From: "Larry" <lljo40@xxxxxxxxxxxx>
- Date: 30 Nov 2005 10:44:44 -0800
I'm already doing that, but the Forms collection are only open forms.
Here is the entire subroutine I have so far. It works for the "main"
form I need to process, but it doesn't process it's subforms (yet).
Public Sub FindRequired(strFormName As String)
'
' Find fields that should be required, based on the label for each
field on the form starting
' with an asterisk.
'
Dim frm As Form
Dim ctl As Control
Dim lbl As Label
Dim blnClose As Boolean
' Use static variables to capture the label and controlsource
names, to be able to make
' this work across recursive calls (for sub forms)
Static strControlList As String, _
strLabelList As String
' If this is the main form, reset the static variables
If strFormName = "frmPersonnel" Then
strControlList = ""
strLabelList = ""
End If
' If the form is loaded, assign it to the form variable
If fIsLoaded(strFormName) Then
Set frm = Forms(strFormName)
Else
' ----- DOESN'T WORK!
' The form is not loaded, so load it then assign it to the form
' DoCmd.OpenForm strFormName, , , , acFormReadOnly, acHidden
' Set frm = Forms(strFormName)
' blnClose = True
End If
' If there is not a form for some reason, exit the subroutine
If frm Is Nothing Then
Exit Sub
End If
' Loop on all the controls on the form
For Each ctl In frm.Controls
' If this is a TextBox or ComboBox process it
If TypeOf ctl Is TextBox Or _
TypeOf ctl Is ComboBox Then
' If it's visible and it has a control attached to it (the
label) then process it
If ctl.Visible And _
ctl.Controls.Count > 0 Then
' The label will be the first control in the
collection, so grab it
Set lbl = ctl.Controls(0)
' If the first character in the labels caption is an
asterisk, it's a required
' field, so capture the label caption (sans asterisk)
and control source
If Left(lbl.Caption, 1) = "*" Then
strControlList = strControlList & ";" &
ctl.ControlSource
strLabelList = strLabelList & ";" &
Mid(lbl.Caption, 2)
End If
End If
ElseIf TypeOf ctl Is SubForm Then
' This is a subform control, so recusively call this
subroutine, passing the
' subform's form name
Call FindRequired(ctl.Form.Name)
End If
Next ctl
' Control processing is finished, if this is the main form, process
what was found
If strFormName = "frmPersonnel" Then
' Strip off the leading semi-colon from the lists
strControlList = Mid(strControlList, 2)
strLabelList = Mid(strLabelList, 2)
Debug.Print strLabelList
Debug.Print strControlList
End If
' If this form was opened during the process, close it
If blnClose Then
DoCmd.Close acForm, strFormName
End If
Set frm = Nothing
End Sub
.
- Follow-Ups:
- Re: Form instance using variable for name
- From: Allen Browne
- Re: Form instance using variable for name
- References:
- Form instance using variable for name
- From: Larry
- Re: Form instance using variable for name
- From: Larry
- Re: Form instance using variable for name
- From: Allen Browne
- Re: Form instance using variable for name
- From: Larry
- Re: Form instance using variable for name
- From: Allen Browne
- Form instance using variable for name
- Prev by Date: Re: Form instance using variable for name
- Next by Date: Questionable DIM Type
- Previous by thread: Re: Form instance using variable for name
- Next by thread: Re: Form instance using variable for name
- Index(es):
Relevant Pages
|