Assistance with Decimal places in VBA script

PatrickWW

Board Regular
Joined
Jun 7, 2013
Messages
135
HTML:
Private Sub Command0_Click()
Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset
Dim strSQL As String
Dim strRptName As String
Dim count As Integer
strRptName = "PT Exports"
strSQL = "Select [IDCode] From CorePData;"
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenForwardOnly)
    With MyRS
    
        Do While Not MyRS.EOF
        DoCmd.OpenReport strRptName, acViewPreview, , "[ProductCode]='" & ![ProductCode] & "'"
        DoCmd.OutputTo acOutputReport, strRptName, acFormatRTF, "C:\Users\userid\my documents\PT\Reports\" & ![ProductCode] & "_NDXPublicationAttributes.doc"
        DoCmd.Close acReport, strRptName, acSaveNo
        .MoveNext
        Loop
    
    End With

MyRS.Close
Set MyRS = Nothing
End Sub
I am generating an SQL report which has a ton of trailing zero's and I was wondering if there was a way to eliminate those at the presentation layer. I read it's a big no-no to do that at the Database level (SQL) Any assistance would be greatly appreciated. This code copies the table and coverts each record into an RTF document. I am not against this going into an CSV or XLSX file, but the big piece is getting the leading zero's to slim down to 4 decimal places to the right. (.0000) no more than that. FYI this is in Access 2010
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi,
Maybe in the SQL you can do this:

Code:
strSQL = "Select Format([IDCode],"#.0000") From CorePData;"
 
Upvote 0
Thanks for the code, however it seems to still bomb out. If you can think of anything else please let me know. I really appreciate it!
 
Upvote 0
Hi,
What kind of data is [IDCode]?
ξ
 
Upvote 0
Is the code a *real* number or a number stored as text? If they are real numbers, do they have decimals (floating point numbers) or are they whole numbers (integers)?


Note:
Thanks for the code, however it seems to still bomb out.
Bomb out how - do you mean still has many trailing zeros?
 
Last edited:
Upvote 0
Not accepting the syntax. Compile Error Expected: End of Statement. The cursor lands on the # sign.
 
Upvote 0
Okay,
sorry. Should be in VBA:
Code:
strSQL = "Select Format([IDCode],""#.0000"") From CorePData;"
 
Upvote 0
X thanks got me through part of the code however in the With MYRS docmd I am getting syntax errors. It seems like it needs to be changed in the bottom half of the script as well. Sorry I'm just starting to learn VBA. Kind regards
 
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,957
Members
449,200
Latest member
indiansth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top