Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 28th, 2007, 03:25 PM
Registered User
 
Join Date: Sep 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Malformed GUID Error runtime 3075

Hello everyone,

I am writing a database for my company. Right now my access file can compare 2 different indices and graph them. My boss recently asked me to put a XIRR function in the access database. However, as my search suggests that Access does not have the XIRR function from excel. So I had to write code to import the function and use it in Access. However, I keep getting malformed GUID error. I believe this is about how I enter the Date.
The code is like this:
Option Compare Database

Private Sub Command0_Click()

Dim db As DAO.Database
Dim rs As DAO.Recordset, strsql$

Dim dIRRresult As Double

Dim dNPVResult As Double

Dim lDiscountRate As Double

Dim objExcel As Excel.Application

Dim ArrDates() As Long

Dim ArrAmounts() As Long

Dim lRecordCount As Long

Dim intCounter As Long


' Initialise the Excel application and register the Analysis toolpak file

Set objExcel = New Excel.Application


objExcel.RegisterXLL objExcel.Application.LibraryPath & "\ANALYSIS\ANALYS32.XLL"


'Initialise the database and the recordset

Set db = CurrentDb

strsql = "SELECT Dowjones.Index, " & " Dowjones.Date, " & " Dowjones.Close " & " FROM [Dowjones]" & "WHERE (Dowjones.Index={'" & [Forms]![sear12X]![tindex] & "'}) AND " & " ([Dowjones.Date]<{'" & [Forms]![sear12X]![tstart] & "'}) AND " & " ([Dowjones.Date]>{'" & [Forms]![sear12X]![tend] & "'})"






Set rs = db.OpenRecordset(strsql, dbOpenDynaset)

lRecordCount = rs.RecordCount


'read the values into the array only of there is more than one value in the cash flow stream. Otherwise the 'functions would not work anyway.


If lRecordCount > 1 Then



'Initialize the arrays which hold the period and cashflow numbers using the recordcount of the recordset

ReDim ArrDates(1 To lRecordCount) As Long

ReDim ArrAmounts(1 To lRecordCount) As Long

'Read the period and cashflow values from the recordset and put them in the arrays.

For intCounter = 1 To lRecordCount

ArrDates(intCounter) = CLng(CDate(rs!Period))

ArrAmounts(intCounter) = rs!NET_AMOUNT

rs.MoveNext

Next intCounter

'Read the Discount rate (for calculating NPV) from wherever you store it.

lDiscountRate = IIf(IsNull(DLookup("Discount_rate", "TABLE", "COLUMN =" & Value)), 0.15, DLookup("Discount_rate", " TABLE ", " COLUMN =" & Value))


'This is the actual call to the XIRR function.

dIRRresult = IIf(IsError(objExcel.Run("XIRR", ArrAmounts, ArrDates)), 0, objExcel.Run("XIRR", ArrAmounts, ArrDates))

dNPVResult = IIf(IsError(objExcel.Run("XNPV", lDiscountRate, ArrAmounts, ArrDates)), 0, objExcel.Run("XNPV", lDiscountRate, ArrAmounts, ArrDates))

End If

rsAssets.MoveNext




objExcel.Quit

Set objExcel = Nothing

End Sub


I got some parts of the code from somewhere on the net. Well i am not sure what is exactly wrong with the code. I believe there is a problem about how I enter the date in the form(sear12X) which is associated with this code. Also I may have messed when converted the SQL query to VBA. If you could help me I will be more than happy. Also as a note, I am not going to have the NPV function. It was just in the code when I copied it. ANyway I dont believe that it is causing the problem. Thanks


 
Old October 1st, 2007, 08:21 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

IRR is available locally in Access in an array. Let me know if you want help with that.



mmcdonal
 
Old October 1st, 2007, 08:27 AM
Registered User
 
Join Date: Sep 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I know there is IRR but I need to use the XIRR function. Does anybody have an idea about that?






Similar Threads
Thread Thread Starter Forum Replies Last Post
hi i got runtime error 13 Type Mismatch error sriharsha345 Access VBA 2 February 21st, 2008 09:30 AM
runtime error dhoward VB.NET 2002/2003 Basics 2 November 1st, 2007 03:30 PM
MS Access ComboBox GUID Error mp01 BOOK: Beginning VB.NET Databases 13 November 24th, 2006 04:12 PM
mysterious error runtime error '451' coyotworks Excel VBA 1 May 12th, 2006 03:57 PM
Guid Error in listview click event Jimson BOOK: Beginning VB.NET Databases 9 February 16th, 2006 01:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.