We help IT Professionals succeed at work.
Get Started

Passing a Function Name in VBA

bikeski
bikeski asked
on
223 Views
Last Modified: 2016-02-11
Hello Experts,

I'd like to pass a function name in VBA. Here is the code used currently

Call function via:
 Range(Cell).Value = StoreSalesSF(BegDate, EndDate)

Open in new window


Current function:
Function StoreSalesSF(BegDate1, EndDate1) As Variant

Dim conSQL As ADODB.Connection
Dim strSQL As String
Dim i As Integer
Dim Total As Variant
Dim rs As ADODB.Recordset

Total = 0
i = 0

  Set conSQL = New ADODB.Connection
  conSQL.Open "DSN=CDHO;Driver={Firebird/InterBase(r) driver};Dbname=192.168.0.205:d:\zzz\gdbcreation\sv1020_012HO.gbb;CHARSET=NONE;UID=BETAVIEW;Client=C:\Windows\SysWOW64\gds32.dll"
  strSQL = SQLStoreSalesSF(BegDate1, EndDate1)
  Set rs = New ADODB.Recordset
  rs.Open strSQL, conSQL, adOpenStatic, adLockOptimistic
     
  If Not rs.EOF Then
    StoreSalesSF = rs.GetRows(-1, 1, "sum_sales")(0, 0)
    If IsNull(StoreSalesSF) Then
       StoreSalesSF = 0
    End If
  Else
    StoreSalesSF = 0
  End If
  conSQL.Close
End Function

Open in new window


I've tried this code but received an error "Expected Array" at line 15  strSQL = SQLName(BegDate1, EndDate1)

 Range(Cell).Value = SumFunctionSF(BegDate, EndDate, "StoreSalesSF") 

Open in new window


New function:


Function SumFunctionSF(BegDate1 As Variant, EndDate1 As Variant, Title1 As String)

Dim conSQL As ADODB.Connection
Dim strSQL, SQLName As String
Dim i As Integer
Dim Total As Variant
Dim rs As ADODB.Recordset

Total = 0
i = 0

  Set conSQL = New ADODB.Connection
  conSQL.Open "DSN=CDHO;Driver={Firebird/InterBase(r) driver};Dbname=192.168.0.205:d:\zzz\gdbcreation\sv1020_012HO.gbb;CHARSET=NONE;UID=BETAVIEW;Client=C:\Windows\SysWOW64\gds32.dll"
  SQLCall = "SQL" & Title1
  strSQL = SQLName(BegDate1, EndDate1)
  Set rs = New ADODB.Recordset
  rs.Open strSQL, conSQL, adOpenStatic, adLockOptimistic
     
  If Not rs.EOF Then
    SumFunctionSF = rs.GetRows(-1, 1, "sum_sales")(0, 0)
    If IsNull(SumFunctionSF) Then
       SumFunctionSF = 0
    End If
  Else
    SumFunctionSF = 0
  End If
  conSQL.Close
End Function 

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2008
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE