formfields and properties

  • Thread starter Thread starter jokobe
  • Start date Start date
J

jokobe

hi ng,

I have tried this question before, but didn't receive a
helpful answer:
1. I want to catch all the form field names
in my database save the names in a table.
2. Then I want to set some properties for the forms
and/or the fields via VBA.

Is there a solution for this, without opening the forms???

Thanks in advance

jokobe
 
I don't believe that you can get the form field names without opening the
forms they are on (though you could open the forms but not show them
(forms("frmMyForm").visible = false) if that is the issue).
 
jokobe

In order to do what you want would will have to open the forms. Here is
some code to get you started.

Public Sub FindFields()
Dim frm As Form, ctl As Control
Dim i As Integer, strSql as String

For i = 0 To CurrentProject.AllForms.Count - 1
DoCmd.OpenForm CurrentProject.AllForms(i).Name, acDesign, , , ,
acHidden
Set frm = Forms(CurrentProject.AllForms(i).Name)
For Each ctl In frm.Controls
If Nz(ctl.ControlSource,"") <> ""
strSql = "INSERT INTO SomeTable ( SomeField ) " _
VALUES ('" & ctl.ControlSource & "')"
DoCmd.SetWarnings False
Docmd.RunSql strSql
DoCmd.SetWarnings True
End If
' Add Code here to satisfy your second condition
Next ctl
Set frm = Nothing
DoCmd.Close acForm, CurrentProject.AllForms(i).Name, acSaveYes
Next i
End Sub

This code (**UNTESTED**) should find all of the fields on all of the forms
and insert the fieldnames into a table satisfying your first condition.
Your second condition can also be resolved with this code by adding
additional logic between the For Each ctl and Next ctl construct to change
whatever properties you want to change.


Ron W
 
thanks Paul, thanks Ron,

although you confirmed me what I feared, there is no work
around. Thanks again

Joachim
 
Back
Top