Please Check

mohammadagul

PrinceAtif
Local time
Today, 11:46
Joined
Mar 14, 2004
Messages
298
I am trying to use the following code to change the Currency field property in all my tables from Currency to Standard.

Function ChangeCurrency()
Dim db as database
Dim tbldef as TableDef
Dim fld as Field
set db = CurrentDb
For Each tbldef in db.TableDefs
If left(tbldef.NAME, 4)<> "Msys" Then
Debug.Print tbldef.NAME
If fld.Type = dbCurrency then
fld.format = "Standard"
End If
Next
End If
Next
End Function
 
mohammadagul said:
I am trying to use the following code to change the Currency field property in all my tables from Currency to Standard.

Code:
Function ChangeCurrency()
    Dim db as database
    Dim tbldef as TableDef
    Dim fld as Field
    set db = CurrentDb
    For Each tbldef in db.TableDefs
        If left(tbldef.NAME, 4)<> "Msys" Then
            Debug.Print tbldef.NAME
            If fld.Type = dbCurrency then
                fld.format = "Standard"
            End If
            [B]Next[/B]
        End If
    Next
End Function

Without even checking your logic, you have one too many "next" s ... you should notice this just but looking at the code hiearchy


**Edit: Looking further into it, you forgot the
For Each fld in tbldef.Fields**
 
Last edited:
It looks like you want something like this:

Code:
Function ChangeCurrency()
    Dim db      As DAO.Database
    Dim tbldef  As DAO.TableDef
    Dim fld     As DAO.Field
    
    Set db = CurrentDb
    
    For Each tbldef In db.TableDefs
        If Left(tbldef.Name, 4) <> "Msys" Then
            For Each fld In tbldef.Fields
                If fld.Type = dbCurrency Then
                    fld.Properties("Format").Value = "Standard"
                    [COLOR=Green]'you may want this for later
                    'db.Execute "ALTER TABLE [" & tbldef.Name & "] ALTER [" & fld.Name & "] Currency"[/COLOR]
                End If
            Next
        End If
    Next    
End Function
 

Users who are viewing this thread

Back
Top Bottom