passing data between Access and Excel

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to pass data from a an Access query to Excel for mathematical
calculations and then pass the result back into Access to be displayed on a
form? I would appreciate any type of help. Thanks a lot!
 
It is possible to call Excel functions from Access.
It is also possible that Access can compute the values directly.
It depends on your exact requirements.

================================================

How to Use Excel Functions in Access:

It would be very nice if I could call an excel function like yield directly
from a query.
Can this be done? If so, how?

Well, there are Excel functions and then there are Excel Add-ins (which
unfortunately includes Yield). The core worksheet functions can be included
as follows:

1. Open your database, type Ctrl+G to make sure you're in the VBA editor.
2. Choose Tools\References, and scroll down and check Microsoft Excel 10.0
Object Library (or whatever version of the Excel Object Library you have)
3. Use the functions as Excel.WorkSheetFunction.FunctionName, for example if
you type:
?Excel.WorksheetFunction.Ceiling(5,3)
in the immediate pane and hit enter, it should return 6.
4. To use such functions in queries, make a wrapper function by passing
appropriate data to the Excel function and returning the results, for
example:
Function MyCeiling(ByVal iOne As Double, ByVal iTwo As Double)
MyCeiling = Excel.WorksheetFunction.Ceiling(iOne, iTwo)
End Function
5. Call that wrapper function from queries, as in:
Result: MyCeiling([field1],[field2])

The Yield function, however, is a special case, as it's an Excel Add-in. If
you're *really* intent on using it, you can access it from automation, see:
http://support.microsoft.com/default.aspx?scid=kb;EN-GB;q198571

Probably best to develop your own library of functions: there are VB/VBA
versions out there for almost anything that you might need.

Originally posted by Max Dunn
============================================================


You can always write your own functions to do the same thing as Excel.

Here are 3 common ones: Floor, Ceiling and Round

Function Floor(N, ByVal Precision)
'
' Similar to Excel's Floor function
' Rounds down (toward zero) to the next higher level of precision.
' Precision cannot be 0.
'
Precision = Abs(Precision)
Floor = Int(N / Precision) * Precision
End Function


Function Ceiling(N, ByVal Precision)
'
' Similar to Excel's Ceiling function
' Rounds up to the next higher level of precision.
' Precision cannot be 0.
'
Dim Temp As Double
Precision = Abs(Precision)
Temp = Int(N / Precision) * Precision
If Temp = N Then
Ceiling = N
Else
Ceiling = Temp + Precision * Sgn(Temp)
End If
End Function

Function RoundN(X, N As Integer)
'
' Rounds a number to N decimal places
' Uses arithmatic rounding
' N should be in the range 0-10 for proper results
'
Dim Factor As Long
Factor = 10 ^ N
RoundN = Int(X * Factor + 0.5) / Factor
End Function

=====================================================
 
Back
Top