Change format on all text boxes

S

SimeonD

Hi
I wish to change the format on all text boxes from 'Euro' to 'Standard'
I have code for looping through each form. What I'm unsure of is how to loop
through each control, check if its a text box, and then setting its format
to Standard.
Any ideas?
Thanks
Simeon


Dim objDAP As AccessObject
Dim f As Form
For Each objDAP In CurrentProject.AllForms

If (True) Then
i = i + 1
DoCmd.OpenForm objDAP.Name, acDesign
Set f = Forms(objDAP.Name)
 
A

Allen Browne

To loop the controls on a form, and identify the text boxes and combos:

Dim objDAP As AccessObject
Dim f As Form
Dim ctl As Control
Dim strForm As String

For Each objDAP In CurrentProject.AllForms
strForm = objDAP.Name
DoCmd.OpenForm strForm, acDesign, WindowMode:=acHidden
Set f = Forms(strForm)

For Each ctl in f.Controls
Select case ctl.ControlType
Case acTextBox, acComboBox
Debug.Print ctl.Format
End Select
Next

DoCmd.Close acForm, strForm
Next
 
S

SimeonD

Thank you.
Based on what you sent, here's what I used:

Dim objDAP As AccessObject
Dim f As Form
Dim ctl As Control
Dim strForm As String
Const conSTANDARD As String = "Standard"
Const conEURO As String = "Euro"
Dim bChanged As Boolean

For Each objDAP In CurrentProject.AllForms
strForm = objDAP.Name

' Don't check for this form
If objDAP.Name <> Me.Name Then

DoCmd.OpenForm strForm, acDesign, WindowMode:=acHidden
Set f = Forms(strForm)

For Each ctl In f.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox
If ctl.Format = conEURO Then
' Change made, so save requried
bChanged = True
ctl.Format = conSTANDARD
End If
End Select
Next

If bChanged Then
bChanged = False
DoCmd.Close acForm, objDAP.Name, acSaveYes
Else
DoCmd.Close acForm, objDAP.Name, acSaveNo
End If
End If

Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top