Number format in queries

T

Tom Telford

Hopefully this is easy.

Does anyone know if it is possible to change the default number format for
number fields to "standard" (or any other format). I'm getting very tired of
going into properties all the time to flip the setting so that large numbers
are actually readable.


Thanks,

Tom.
 
A

Allen Browne

Tom Telford said:
Does anyone know if it is possible to change the default number format for
number fields to "standard" (or any other format). I'm getting very tired
of
going into properties all the time to flip the setting so that large
numbers
are actually readable.

Tom, there's not an easy way to do this in the interface, but you can do it
programmatically. Adjust the Select Case part for the field types you want
to handle.

Public Function FormatQueryNumbers(Optional strQueryName As String)
'Purpose: Set the Format of numeric fields in queries to Standard.
'Argument: Name of query to set. If blank, ALL queries are set.
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strMsg As String

Set db = CurrentDb()
If strQueryName <> vbNullString Then
Set qdf = db.QueryDefs(strQueryName)
strMsg = "About to set the Format to Standard for all numeric fields
in query " & strQueryName & vbCrLf & "Proceed?"
If MsgBox(strMsg, vbYesNo, "Confirm") = vbYes Then
Call FormatQueryNumbers2(qdf)
End If
Else
strMsg = "About to set the Format to Standard for all numeric fields
in ALL QUERIES in this database." & vbCrLf & "Proceed?"
If MsgBox(strMsg, vbYesNo, "Confirm") = vbYes Then
For Each qdf In db.QueryDefs
If Not (qdf.Name Like "~*") Then
Call FormatQueryNumbers2(qdf)
End If
Next
End If
End If

Set qdf = Nothing
Set db = Nothing
End Function

Private Function FormatQueryNumbers2(qdf As DAO.QueryDef)
Dim fld As DAO.Field

For Each fld In qdf.Fields
Select Case fld.Type
Case dbDouble, dbSingle ', dbLong, dbInteger, dbByte
Call SetPropertyDAO(fld, "Format", dbText, "Standard")
Debug.Print qdf.Name & "." & fld.Name
End Select
Next
End Function
 
T

Tom Telford

Thanks Allen. Does this change the default for all future queries in the
database as well?

Thanks,

Tom.



:
 
A

Allen Browne

No: you need to run it over specific queries, so future ones are not
affected.
 
Top