Re: Form instance using variable for name



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

.



Relevant Pages

  • Re: Write, Move, Delete text on PictureBox
    ... Public Function WYSIWYG_TextBoxText(TB As TextBox) As String ... Simply place a Label control ... Now, whenever you want create a Label, you would just use ... Err.Raise 10001, "InitializeTextBox Subroutine", _ ...
    (comp.lang.basic.visual.misc)
  • Re: Is this a Sound Database Design? -- code: SwitchTabs
    ... The "command buttons" (put in quotes because I actually used label ... Dummy is an unbound control -- really tiny because I use labels instead ... Sometimes, the subforms do not have linking fields, like a lookup subform ... Dim mCurrentTab As Integer, i As Integer, mBoo As Boolean ...
    (microsoft.public.access.tablesdbdesign)
  • Re: For each Control Hauptform
    ... Dim Label1 As New Label ... If TypeOf MyControl Is Label Then ... Private Function FindControl(ByVal parent As Control, ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: Auto Fill Date
    ... Include an unbound control set to a valid date format. ... Dim ctl As Control ... Next add labels to the Page Header of your report. ... Set each of these Label control's Tag property to X ...
    (microsoft.public.access.reports)
  • Re: Createform, no FormHeader
    ... up to just before the CreateControl for the label. ... I had to remove the Parent parameter in the CreateControl ... Dim stLinkCriteria As String ... Dim ctlLabel As Control, ctlText As Control ...
    (microsoft.public.access.formscoding)