I have spinning cycles on attempting to Round Down within VBA. The code is as follows. I would appreciate any assistance. Line 102 is where it is generating a compiler error of "Method or data member not found." -
Private Sub Create_tbl_SOData_Table()
-
-
On Error GoTo Err_Hndlr
-
-
-
strFirstRec = "Yes"
-
-
' **** initialize temporary fields, date is set to dummy initial date, it has no meaning
-
-
strTempSalesOrderId = 0
-
strTempSalesOrderNo = " "
-
strTempPO = " "
-
strTempPOID = 0
-
strTempUnitPrice = 0
-
strTempExtendedPrice = 0
-
strTempShipmentPrice = " "
-
strTempAccountCode = " "
-
strTempInd = "D"
-
strTempFund = " "
-
strTempIndexOrg = " "
-
strTempRule = "J099"
-
strTempPOLineNo = 0
-
strTempDate = "03/19/2007"
-
strTempBuyer = " "
-
strTempProductDescription = " "
-
strTempQuantity = 0
-
strTempSKUCatalog = " "
-
-
Dim dbs As DAO.Database
-
Dim rstTemp As DAO.Recordset
-
Dim strSQL As String
-
-
Set dbs = CurrentDb()
-
-
'**** create output table
-
'Delete temporary tabl
-
DoCmd.RunSQL "DROP TABLE tbl_SOData;"
-
-
strSQL = "SELECT SO_Data_Formatted.[Sales Order Id], " & _
-
"SO_Data_Formatted.[Sales Order No], " & _
-
"SO_Data_Formatted.[PO #], " & _
-
"SO_Data_Formatted.[PO ID], " & _
-
"SO_Data_Formatted.[Unit Price], " & _
-
"SO_Data_Formatted.[Extended Price], " & _
-
"SO_CFSummary.[Shipment Price], " & _
-
"SO_CFSummary.Account AS [Account Code], 'D ' AS Ind, " & _
-
"SO_CFSummary.Fund, " & _
-
"SO_CFSummary.Index AS IndexOrg, " & _
-
"'J099 ' AS RuleCode, " & _
-
"SO_Data_Formatted.[PO Line #], " & _
-
"SO_Data_Formatted.SODate, " & _
-
"SO_Data_Formatted.[Buyer: First Name], " & _
-
"SO_Data_Formatted.[Product Description], " & _
-
"SO_Data_Formatted.Quantity, " & _
-
"SO_Data_Formatted.[SKU/Catalog #], " & _
-
"SO_Data_Formatted.[Sales Order No] " & _
-
"FROM SO_CFSummary " & _
-
"INNER JOIN SO_Data_Formatted " & _
-
"ON (SO_CFSummary.[Sales Order Line Number] = SO_Data_Formatted.[PO Line #]) " & _
-
"AND (SO_CFSummary.[Sales Order Id] = SO_Data_Formatted.[Sales Order Id]) " & _
-
"WHERE (((SO_Data_Formatted.[SODate]) Between #" & [Forms]![F_Import_DATA]![txb_date_start] & "# And #" & [Forms]![F_Import_DATA]![txb_date_end] & "#)) " & _
-
"ORDER BY SO_Data_Formatted.[Sales Order No];"
-
-
'Create temporary table
-
CurrentDb.Execute ("CREATE TABLE tbl_SOData( [Sales Order Id] Integer, " & _
-
"[Sales Order No#] Varchar (10), " & _
-
"[PO #] Varchar(8), " & _
-
"[PO ID] Integer, " & _
-
"[Unit Price] money, " & _
-
"[Extended Price] money, " & _
-
"[Shipment Price] money, " & _
-
"AccountCode Varchar(6), " & _
-
"Ind Varchar(1), " & _
-
"Fund Varchar(6), " & _
-
"IndexOrg Varchar(6), " & _
-
"RuleCode VARCHAR(4), " & _
-
"[PO Line No#] Integer, " & _
-
"S0Date DATETIME, " & _
-
"Buyer VARCHAR(50), " & _
-
"[Product Description] VARCHAR(150), " & _
-
"Quantity Integer, " & _
-
"[SKU/Catalog #] VARCHAR(50))")
-
-
Set rstTemp = dbs.OpenRecordset(strSQL)
-
Set rstSummary = CurrentDb.OpenRecordset("tbl_SOData")
-
-
rstTemp.MoveFirst
-
-
Do While rstTemp.EOF = False
-
-
If strFirstRec = "Yes" Then
-
strFirstRec = "No"
-
End If
-
-
strTempSalesOrderId = rstTemp![Sales Order Id]
-
strTempSalesOrderNo = rstTemp![Sales Order No]
-
strTempPO = rstTemp![PO #]
-
strTempPOID = rstTemp![PO ID]
-
-
If Not IsNull(rstTemp![Unit Price]) Then
-
strTempUnitPrice = rstTemp![Unit Price]
-
strTempUnitPrice = Application.WorksheetFunction.RoundDown(strTempUnitPrice, 2)
-
Else
-
strTempUnitPrice = 0
-
End If
-
If Not IsNull(rstTemp![Extended Price]) Then
-
strTempExtendedPrice = Application.WorksheetFunction.RoundDown((rstTemp![Extended Price]), 2)
-
Else
-
strTempExtendedPrice = 0
-
End If
-
If Not IsNull(rstTemp![Shipment Price]) Then
-
strTempShipmentPrice = Application.WorksheetFunction.RoundDown((rstTemp![Shipment Price]), 2)
-
Else
-
strTempShipmentPrice = 0
-
End If
-
strTempAccountCode = rstTemp![Account Code]
-
-
strTempFund = rstTemp!Fund
-
strTempIndexOrg = rstTemp!IndexOrg
-
strTempPOLineNo = rstTemp![PO Line #]
-
strTempDate = rstTemp![SODate]
-
strTempBuyer = rstTemp![Buyer: First Name]
-
strTempProductDescription = rstTemp![Product Description]
-
strTempQuantity = rstTemp![Quantity]
-
strTempSKUCatalog = rstTemp![SKU/Catalog #]
-
-
-
rstSummary.AddNew
-
-
rstSummary![Sales Order Id] = strTempSalesOrderId
-
rstSummary![Sales Order No#] = strTempSalesOrderNo
-
rstSummary![PO #] = strTempPO
-
rstSummary![PO ID] = strTempPOID
-
rstSummary![Unit Price] = strTempUnitPrice
-
rstSummary![Extended Price] = strTempExtendedPrice
-
rstSummary![Shipment Price] = strTempShipmentPrice
-
rstSummary!AccountCode = strTempAccountCode
-
rstSummary!Ind = strTempInd
-
rstSummary!Fund = strTempFund
-
rstSummary!IndexOrg = strTempIndexOrg
-
rstSummary!RuleCode = strTempRule
-
rstSummary![PO Line No#] = strTempPOLineNo
-
rstSummary!S0Date = strTempDate
-
rstSummary!Buyer = strTempBuyer
-
rstSummary![Product Description] = strTempProductDescription
-
rstSummary!Quantity = strTempQuantity
-
rstSummary![SKU/Catalog #] = strTempSKUCatalog
-
-
-
rstSummary.Update
-
-
-
strTempSalesOrderId = 0
-
strTempSalesOrderNo = " "
-
strTempPO = " "
-
strTempPOID = 0
-
strTempUnitPrice = 0
-
strTempExtendedPrice = 0
-
strTempShipmentPrice = " "
-
strTempAccountCode = " "
-
-
strTempFund = " "
-
strTempIndexOrg = " "
-
-
strTempPOLineNo = 0
-
-
strTempBuyer = " "
-
strTempProductDescription = " "
-
strTempQuantity = 0
-
strTempSKUCatalog = " "
-
-
rstTemp.MoveNext
-
Loop
-
-
rstTemp.Close
-
rstSummary.Close
-
-
-
Create_tbl_SOData_Exit:
-
Exit Sub
-
A VBA specific approach might be to use the Fix() function. This returns a rounded down integral value, but would need to be used with multiplying and dividing to handle numbers of decimal places : - strTempUnitPrice = CDbl(Fix(Val(strTempUnitPrice) * 100)) / 100
I assume you know the limitations of storing your numeric values in string variables.
8 3390
I'm a little confused, dowlingm815. Are you attempting to utilize Excel's RoundDown() Worksheet Function from within Access in Line #102? If so, that approach will never work.
Hey Adezii,
Nice to hear from you. Yes, I need to round down, if the price is 2.667, it needs to drop the values pass the second digit, 2.66. I've tired cast, decimal, I'm running out of ideals.
Mary
NeoPa 32,556
Expert Mod 16PB
My best guess is that the OP is trying to do just that ADezii. It's hard to be sure because there is so little information in the question other than hundreds of lines of code. I can't say I'm overly amused.
I should make clear that the WorksheetFunction class is a member of the Excel Application object only. This is not general VBA, and needs to be made available to an Access Project ( Tools / References in the VBA IDE) before use. It would then be referenced as : - Excel.WorksheetFunction.RoundDown()
F2 from the VBA IDE provides a way (The Object Browser) to negotiate the class structures associated with each application or library. This can be extremely helpful for a developer.
NeoPa 32,556
Expert Mod 16PB
A VBA specific approach might be to use the Fix() function. This returns a rounded down integral value, but would need to be used with multiplying and dividing to handle numbers of decimal places : - strTempUnitPrice = CDbl(Fix(Val(strTempUnitPrice) * 100)) / 100
I assume you know the limitations of storing your numeric values in string variables.
- 'NOTE: You must 1st set a Reference to the Microsoft Excel XX.X Object Library
-
Dim appExcel As Excel.Application 'Declare in a Broader Scope
-
-
Set appExcel = New Excel.Application
-
-
Debug.Print appExcel.WorksheetFunction.RoundDown("32.519123", 2)
-
-
'Execute after processing Recordset
-
appExcel.Quit
-
Set appExcel = Nothing
OUTPUT: NeoPa 32,556
Expert Mod 16PB Application Automation (as you have illustrated) is actually not necessary ADezii. As long as the Microsoft Excel XX.XX Object Library is referenced, the method can be called (See in post #4 how it is referenced in code).
Good point, NeoPa, and an oversight on my part.
Gentlmen,
Thank you for your assistance. I opted for using for using CDbl(Fix(Val(field))) approach to be consistent with the code. I apppreciate all of your input.
Mary
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Aaron |
last post by:
I am trying to write a Python script file which analyses data in an
iterative manner. During each iteration, I wish to utilise the Solver
function in Excel to perform some constrained, non-linear...
|
by: Jim |
last post by:
Need help with aggregate function...for each unique product, I need the
provider with the cheapest cost factor
Here't the table (Table1)
ID product provider factor
1 123456 abc...
|
by: dibblm |
last post by:
Below is current code used. I can only list one directory then move to next.
I want to search one more directory further and can't seem to find how to
get one deeper. What I want to accomplish is...
|
by: Vasilis X |
last post by:
Hello.
I want to use the excel function Year( ) (or Day, Month, Minute etc...)
in a Visual Basic .net application.
How can i do this?
I tried Excel.WorksheetFunction but this class doesn't...
|
by: doug9149 |
last post by:
Hello all, I've got some code I wrote using VBA for Excel that I'm trying to recreate using C#.NET. The code autofilters 1 entire column from 1 Worksheet from a Workbook and then appends this...
|
by: Carlos |
last post by:
I'm getting RPC error when I try to register analys32.xll in the VB program.
ErrorCode=-2147417851
Message="El servidor lanzó una excepción. (Exception from HRESULT:
0x80010105...
|
by: steveyjg |
last post by:
This is my first post so I'm not sure if this should be in the .NET forum or the VB forum. Anyway I'm using VB .NET and trying to call the Percentile function. The function needs an Object as a...
|
by: lucky33 |
last post by:
I am using the AVG function in a report to show the average number of
cases picked per line item over a given period of time. For instance
the user might want the info from 07/16/07 to 07/20/07.
...
|
by: keirnus |
last post by:
Hello once again...
I made a function in Excel. The function does some error checking within the Excel file.
To be easy for me, I want my code in MS Access to simply call the function in Excel....
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |