Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default What is wrong?

I have created the following function:

Public Function GetProjectInfo(pid) As Variant()

strProjectQuery = "SELECT P_NAME, P_FUND, P_BORG FROM Projects " & _
"WHERE P_ID=" & pid
Set prs = CurrentDb().OpenRecordset(strProjectQuery)
If Not prs.BOF And Not prs.EOF Then
p = Array(prs!P_NAME, prs!P_FUND, prs!P_BORG)
Else
p = Array("No Data")
MsgBox "No matching Project record. " & _
"Please contact your Database Administrator."
End If
End Function

I invoke the function with:

Dim ProjInfo As Variant
ProjInfo = Utils.GetProjectInfo(strRecNo)


When I invoke it, I get an array that is filled (determined with the IsArray
and IsEmpty methods), but when I try to loop through the array or use UBound
or LBound, I get a "subscript is out of range" error.

What do I need to do to fix it.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default What is wrong?

In your function where do you set the return value... The last line should be
something like...

GetProjectInfo = p

HTH

"Andy Dorph" wrote:

I have created the following function:

Public Function GetProjectInfo(pid) As Variant()

strProjectQuery = "SELECT P_NAME, P_FUND, P_BORG FROM Projects " & _
"WHERE P_ID=" & pid
Set prs = CurrentDb().OpenRecordset(strProjectQuery)
If Not prs.BOF And Not prs.EOF Then
p = Array(prs!P_NAME, prs!P_FUND, prs!P_BORG)
Else
p = Array("No Data")
MsgBox "No matching Project record. " & _
"Please contact your Database Administrator."
End If
End Function

I invoke the function with:

Dim ProjInfo As Variant
ProjInfo = Utils.GetProjectInfo(strRecNo)


When I invoke it, I get an array that is filled (determined with the IsArray
and IsEmpty methods), but when I try to loop through the array or use UBound
or LBound, I get a "subscript is out of range" error.

What do I need to do to fix it.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is the wrong? rajaiy Excel Worksheet Functions 0 July 27th 09 11:45 AM
What am I doing wrong aussiegirlone Excel Discussion (Misc queries) 15 July 18th 09 10:08 AM
Insert Calculated Field (wrong Qty*Price = wrong Amount) Edmund Excel Discussion (Misc queries) 8 October 4th 07 12:13 PM
What am I doing wrong? Jeff New Users to Excel 4 March 6th 05 03:05 AM
What do i wrong here Dick Kusleika[_3_] Excel Programming 0 August 11th 04 08:40 PM


All times are GMT +1. The time now is 10:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"