I can run this sql from another db in the 'access vba enviroment' and it runs fine. There is a function 'GetOwners' used in the query. If I try within the 'arcgis vba enviroment', the function isn't recognized.
Any thoughts?
This is the query
And this is the function
Any thoughts?
This is the query
Code:
Public Sub MakeSearchBook()
Dim Mydb As DAO.Database
Set Mydb = OpenDatabase("G:\Common\Access_Databases\New Folder\DB_Tables\MetallicMineralsTables.mdb")
Mydb.Execute "SELECT DISTINCTROW ALLDISP.[Disposition Number] AS Disp_num, ALLDISP.[Current Status], GetOwners([ALLDISP].[Disposition Number]) AS OWNERS, ALLDISP.Location, ALLDISP.[Area (Hectares)], ALLDISP.[NTS Map Reference], ALLDISP.[Effective Date], ALLDISP.[Grouping Certificate], ALLDISP.[Mining District], ALLDISP.[Total Available Expenditures], ALLDISP.[Assessment work awaiting approval by Geology Branch (Y/N)], ALLDISP.[Date Protected to] AS [In Good Standing to], ALLDISP.[Applied Assessment work for year ending], ALLDISP.Incurred, ALLDISP.[Not Incurred], ALLDISP.[Relief from Assessment Work], ALLDISP.[Non-Refundable Cash Deposit] " & _
"INTO [DBASE 5.0;DATABASE=C:\].[Test1.dbf] " & _
"FROM ALLDISP " & _
"WHERE (((ALLDISP.[Current Status]) Like 'ACT*')) " & _
"ORDER BY ALLDISP.[Disposition Number]"
End Sub
Code:
Public Function GetOwners(Dispos As String) As String
' MAKE THE OWNER string
Dim qdfGetOwners As DAO.QueryDef
Dim rstGetOwners As DAO.RecordSet
Dim strSQL As String
Dim strOWNERS As String
Dim db As DAO.Database
Set db = OpenDatabase("G:\Common\Access_Databases\New Folder\DB_Tables\MetallicMineralsTables.mdb")
Set qdfGetOwners = db.CreateQueryDef("")
strSQL = "SELECT tblHolders.DispositionNumber, tblHolders.Holder, tblHolders.Percentage " & _
"FROM tblHolders " & _
"WHERE (((tblHolders.DispositionNumber)='" & Dispos & "')) " & _
"ORDER BY tblHolders.Percentage DESC"
With qdfGetOwners
.SQL = strSQL
Set rstGetOwners = .OpenRecordset()
End With
With rstGetOwners
Do While Not .EOF
If .OpenRecordset.Fields(0).Value = Dispos Then
strOWNERS = strOWNERS & .Fields(1).Value & " " & .Fields(2).Value & "%" & " "
End If
.MoveNext
Loop
strOWNERS = RTrim(strOWNERS)
End With
rstGetOwners.Close
GetOwners = strOWNERS
End Function