|
-
Oct 18th, 2004, 04:40 PM
#1
Thread Starter
Member
FormatNumber function in VBA???
I need to set the length of a variable based on user input in Access VBA. I'm using the function FormatNumber to do that in VB 6.0. The formatnumber function works like this:
FormatNumber(1.1, 5) = 1.100
FormatNumber(2.45, 3) = 2.5
etc.
Is there a similar function in VBA that performs the same task???
-
Oct 18th, 2004, 11:05 PM
#2
Access (and all Office VBA) has something similar to NumberFormat
in VB6. Its NumberFormat. 
What version of Access are you running? Maybe its an earlier
version that doesnt have it for some reason? But it should be
there in all versions.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 19th, 2004, 09:43 AM
#3
Thread Starter
Member
I'm running Access 97 and it doesn't work. ??? It's no problem. I found another way to accomplish the same task:
dim numlength as integer
dim numstring as string
do while len(numstr) < numlength
numstring = numstring & "0"
loop
dim thenum as double
thenum = 1.1
thenum = format(thenum, "0." & numstring)
-
Oct 19th, 2004, 11:01 AM
#4
Ok, dont have 97 anymore so couldnt test. Only have 2000, 2002,
2003. Its in all of those. You know that having the var as a double, it will not round like the NumberFormat function does?
VB Code:
Option Explicit
Private Sub Form_Load()
Dim thenum As Double
thenum = 2.45
thenum = Format(thenum, "0.0000") '=2.4500 and not 2.5000
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|