全局更改所有表单上所有货币字段的货币格式

时间:2013-04-04 07:06:37

标签: ms-access-2007 currency currency-formatting

我刚刚建立了一个包含几种形式的数据库系统。表格有货币字段。我在Windows和英语Access 2007中有一个美国英语语言设置。所以我想这就是我得到$ x,xxx.yy格式的原因。我继续并完成了系统;我只设置了格式为货币,所以我认为实际的格式在其他地方。

数据库字段也只设置为货币。

现在这将在瑞典机器上使用。如何设置全球货币格式,以便它们不会以$ x,xxx.yy格式显示货币,而无需编辑每个表单上的所有字段?

(也就是说,它们应该仍然具有格式:货币,并且存储在数据库中并在字段中显示的确切数字应该以正确的瑞典格式显示。)

2 个答案:

答案 0 :(得分:1)

此代码尚未经过全面测试,但它可能对您有所帮助。在尝试之前备份数据库。

其目的是将({偷偷摸摸地)Access存储的Format类似于$#,##0.00;($#,##0.00)的属性替换为通用值Currency

Sub TweakCurrencyFormats()
Dim cdb As DAO.Database, tbd As DAO.TableDef, fld As DAO.Field
Dim ao As AccessObject, frm As Form, ctl As Control
Set cdb = CurrentDb

Debug.Print "Processing tables..."
For Each tbd In cdb.TableDefs
    For Each fld In tbd.Fields
        If fld.Type = 5 Then  '' Currency
            Debug.Print "[" & tbd.Name & "].[" & fld.Name & "]"
            fld.Properties("Format").Value = "Currency"
            fld.Properties("CurrencyLCID").Value = 1053  '' Swedish
        End If
    Next
    Set fld = Nothing
Next
Set tbd = Nothing

Debug.Print "Processing forms..."
For Each ao In CurrentProject.AllForms
    If Not ao.IsLoaded Then
        DoCmd.OpenForm ao.Name, acDesign
    End If
    Set frm = Application.Forms(ao.Name)
    For Each ctl In frm.Controls
        If ctl.Properties("ControlType").Value = 109 Then  '' text box
            If Left(ctl.Properties("Format").Value, 1) = "$" Then
                Debug.Print "[" & ao.Name & "].[" & ctl.Name & "]"
                ctl.Properties("Format").Value = "Currency"
            End If
        End If
    Next
    Set ctl = Nothing
    Set frm = Nothing
Next
Set ao = Nothing

Set cdb = Nothing
End Sub

答案 1 :(得分:0)

It's impossible.

我会稍微离开这一点。如果你能提供一个聪明的解决方案,而不必手动编辑所有表格,我很乐意接受你的,而不是这个。 :)

相关问题