Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro\Excel\export to Access and Active X

Status
Not open for further replies.

Karebear

MIS
Aug 15, 2002
34
US
I have a user who is using a macro in Excel 2000 to export into Access and is getting an ActiveX component can't create object error when they try to run it...I don't know if is helpful or not but I am including the code behind the macro...I can't find anything about what is causing this.
Function VLookup2Values(DataSet As Range, FirstVal As Variant, FirstCol As Integer, SecondVal As Variant, SecondCol As Integer, ReturnCol As Integer)
Dim FirstRow, LastRow, CheckRow As Integer

FirstRow = 1
LastRow = DataSet.Rows.Count

Do While FirstRow = FirstRow

'Determine if we are on last iteration and check all boundary values
If LastRow - FirstRow < 2 Then

'Check lastrow
If DataSet.Cells(LastRow, FirstCol).Value = FirstVal And DataSet.Cells(LastRow, SecondCol).Value = SecondVal Then
VLookup2Values = DataSet.Cells(LastRow, ReturnCol).Value
Exit Function
End If

'If not last row, return frist row
VLookup2Values = DataSet.Cells(FirstRow, ReturnCol).Value
Exit Function

End If

CheckRow = CInt((FirstRow + LastRow) / 2)

'Because Excel does not handle sorting correctly for strings
If TypeName(DataSet.Cells(CheckRow, FirstCol).Value) = "String" Then
FirstCheck = UCase(DataSet.Cells(CheckRow, FirstCol).Value) >= UCase(FirstVal)
Else
FirstCheck = DataSet.Cells(CheckRow, FirstCol).Value >= FirstVal
End If

If FirstCheck Then

If DataSet.Cells(CheckRow, FirstCol).Value = FirstVal Then


If DataSet.Cells(CheckRow, SecondCol).Value = SecondVal Then
If DataSet.Cells(CheckRow, SecondCol).Value = SecondVal Then
VLookup2Values = DataSet.Cells(CheckRow, ReturnCol).Value
Exit Function
End If
End If

If TypeName(DataSet.Cells(CheckRow, SecondCol).Value) = "String" Then
SecondCheck = UCase(DataSet.Cells(CheckRow, SecondCol).Value) > UCase(SecondVal)
Else
SecondCheck = DataSet.Cells(CheckRow, SecondCol).Value > SecondVal
End If

If SecondCheck Then
'If we haven't exited, then next iteration is up
LastRow = CheckRow
End If
Else
LastRow = CheckRow
End If


End If

'If we haven't identified direction as up, then its down
If LastRow <> CheckRow Then
FirstRow = CheckRow
End If
Loop

VLookup2Values = "#VALUE!"
Exit Function
End Function

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top