matt beamish
Registered User.
- Local time
- Today, 17:03
- Joined
- Sep 21, 2000
- Messages
- 215
I am using a utility put up on line here :
http://www.peterssoftware.com/mlm.htm
to represent spatial data using Googlemaps from within an Access database.
I am using the mapping function with app. 2000 pieces of project data, that has OSGB coordinates, that are converted on the fly to lat lng. These are then mapped by the mapping function.
On an unfiltered/complete dataset, the mapping function runs fine.
As there is so much data, I want to filter it down, so that users are only presented with a mapping pin for the the current record and those that are within a range of it. So I have used an unbound control (Distancecntrl) on a form to hold a range variable which is used in a selection query to restrict the dataset.
Query definition is
The query that filters/restrict the dataset runs fine to show a subset of the records, but this query is effectively rejected by the mapping function.
The error message (Error in FMLMMMapit (3), object DAO.Database 3061 - Too few parameters. Expected 2.) points to this bit of VBA:
From reading around, I can see that there are problems with accessing the values in Form controls when accessed from VBA. So I have instead tried setting TempVars for my variables, but that doesnt stop the problem. Have also tried using Qrydefs this evening (commented out in the code below), but I have not had success there either.
Can anyone help on this?
The complete function is here:
thanks
http://www.peterssoftware.com/mlm.htm
to represent spatial data using Googlemaps from within an Access database.
I am using the mapping function with app. 2000 pieces of project data, that has OSGB coordinates, that are converted on the fly to lat lng. These are then mapped by the mapping function.
On an unfiltered/complete dataset, the mapping function runs fine.
As there is so much data, I want to filter it down, so that users are only presented with a mapping pin for the the current record and those that are within a range of it. So I have used an unbound control (Distancecntrl) on a form to hold a range variable which is used in a selection query to restrict the dataset.
Query definition is
Code:
Between ([Forms]![F_LocationConversiontoLatlong]![East]-[Forms]![F_LocationConversiontoLatlong]![Distancecntrl]) And ([Forms]![F_LocationConversiontoLatlong]![East]+[Forms]![F_LocationConversiontoLatlong]![Distancecntrl])
The query that filters/restrict the dataset runs fine to show a subset of the records, but this query is effectively rejected by the mapping function.
The error message (Error in FMLMMMapit (3), object DAO.Database 3061 - Too few parameters. Expected 2.) points to this bit of VBA:
Code:
Set rst = dbs.OpenRecordset("Select * from [" & pstrTableOrQueryName & "];", dbOpenForwardOnly)
From reading around, I can see that there are problems with accessing the values in Form controls when accessed from VBA. So I have instead tried setting TempVars for my variables, but that doesnt stop the problem. Have also tried using Qrydefs this evening (commented out in the code below), but I have not had success there either.
Can anyone help on this?
The complete function is here:
Code:
Function fMLMMapIt( _
pstrTableOrQueryName As String _
, Optional pstrLatitudeFieldName As String = "lat" _
, Optional pstrLongitudeFieldName As String = "lng" _
, Optional pstrMapPointColorFieldName As String = "MapPointColor" _
, Optional pstrMapPointLetterFieldName As String = "MapPointLetter" _
, Optional pstrPopUpInfoFieldName As String = "PopUpInfo" _
) As Integer
'******************************************************************************
'* Peter De Baets, author
'* 5/23/2011
'* This routine updates empty latitude and longitude field values in an "Addresses"
'* table. It first removes any apartment number in the address string (see query
'* "qryAddressesNoApt"), then uses the Google Geocoding API to get the lat and lng
'* values, then updates all rows of the Addresses table that have the same address
'* minus the apartment number. This method makes the most efficient use of the
'* Google Geocoding API.
'*
'* A reference to DAO, and Microsoft XML, v6.0 is required for this routine to run
'******************************************************************************
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim loc As LatLng
Dim Knt As Integer
Dim strsql As String
Dim strLastError As String
Dim intErr As Integer
Dim Rtn As Integer
Dim strTempTableName As String
Dim dblLat As Double
Dim dblLng As Double
Dim strPhase As String
Dim strColor As String
Dim strLetter As String
Dim strPopUpInfo As String
Dim LLK(400) As LatLng
Dim LLKSub As Integer
Dim FoundIt As Integer
Dim i As Integer
Dim j As Integer
Dim Marker As Integer
'v1.3
Dim strLat As String
Dim strLng As String
Dim strDecimalPoint As String
Dim strTempQueryName As String
Dim qdf As DAO.QueryDef
Dim strFolder As String
Dim strOutputFileName As String
Dim strExistingTableName As String
Dim tdf As DAO.TableDef
On Error GoTo Err_Section
Marker = 1
If fIsConnectedToInternet Then
Else
GoTo Exit_Section
End If
Marker = 2
Set dbs = CurrentDb()
Marker = 3
'DoCmd.Print pstrTableOrQueryName
'* v1.2
strDecimalPoint = Mid(CStr(3 / 2), 2, 1)
'mb added the following
'Set qdf = dbs.QueryDefs("Q_project_return_latlong")
'qdf("Forms!F_LocationConversiontoLatlong!East") = Forms!F_locationconversiontolatlong!East
'qdf("Forms!F_locationconversiontolatlong!North") = Forms!F_locationconversiontolatlong!North
'qdf("Forms!F_locationconversiontolatlong!distancecntrl") = Forms!F_locationconversiontolatlong!Distancecntrl
Set rst = dbs.OpenRecordset("Select * from [" & pstrTableOrQueryName & "];", dbOpenForwardOnly)
If rst.EOF Then
MsgBox "No records found for mapping", , "Multi-Location Mapper"
GoTo Exit_Section
End If
strTempTableName = "tblMLMTemp1"
'* delete temp table
On Error Resume Next
DoCmd.DeleteObject acTable, strTempTableName
Err.Clear
On Error GoTo Err_Section
Marker = 4
If conMLMAdjustDuplicateMapPointPositions Then
'* Initialize Latitude Longitude Knt (LLK) array
For LLKSub = 0 To 400
LLK(LLKSub).Knt = 0
Next LLKSub
LLKSub = -1
End If
i = 0
Do While Not rst.EOF
i = i + 1
Marker = 5
dblLat = rst(pstrLatitudeFieldName)
dblLng = rst(pstrLongitudeFieldName)
Marker = 6
strPhase = rst!Phase 'mb& ", " & rst!city & " " & rst!st
'Debug.Print strPhase
'* Available colors are:
'*
'* blue
'* brown
'* darkgreen
'* green
'* orange
'* paleblue
'* pink
'* purple
'* red
'* yellow
Marker = 7
If Trim("" & rst(pstrMapPointColorFieldName)) = "" Then
strColor = "red"
Else
Marker = 8
strColor = rst(pstrMapPointColorFieldName)
End If
'* Can be any Capital letter of the English alphabet
Marker = 9
If Trim("" & rst(pstrMapPointLetterFieldName)) = "" Then
strLetter = "A"
Else
Marker = 10
strLetter = rst(pstrMapPointLetterFieldName)
End If
'* This is the text that pops up when the mouse cursor is over the map pin point marker
Marker = 11
If Trim("" & rst(pstrPopUpInfoFieldName)) = "" Then
Marker = 12
strPopUpInfo = strPhase & vbCrLf & "lat=" & dblLat & ", lng=" & dblLng
Else
Marker = 13
strPopUpInfo = rst(pstrPopUpInfoFieldName)
End If
'Debug.Print strPopUpInfo
Marker = 14
If conMLMAdjustDuplicateMapPointPositions Then
Marker = 15
FoundIt = False
For j = 0 To 400
If LLK(j).Knt = 0 Then Exit For
If LLK(j).lat = dblLat And LLK(j).lng = dblLng Then
FoundIt = True
LLK(j).Knt = LLK(j).Knt + 1
'* Make a slight adjustment to the map point latitude so that this map point
'* won't completely cover a previous map point.
dblLat = dblLat + (0.00005 * (LLK(j).Knt - 1))
'dblLng = dblLng + (0.00005 * (LLK(j).Knt - 1))
Exit For
End If
Next j
If FoundIt Then
Else
Marker = 16
LLKSub = LLKSub + 1
If LLKSub > 400 Then
' Debug.Print "Some duplicate map points are hidden behind others. You may increase the size of the LLK array to fix this."
Else
LLK(LLKSub).lat = dblLat
LLK(LLKSub).lng = dblLng
LLK(LLKSub).Knt = 1
End If
End If
End If
'* v1.2
If strDecimalPoint <> "." Then
strLat = Replace(dblLat, strDecimalPoint, ".")
strLng = Replace(dblLng, strDecimalPoint, ".")
Else
strLat = dblLat
strLng = dblLng
End If
Marker = 17
If i = 1 Then
Marker = 18
'* Create the temp table
'* v1.2
'strSQL = "Select " & dblLat & " as lat, " & dblLng & " as lng, '' as Location, '' as Color, '' as Letter, '' as PopUpInfo into [" & strTempTableName & "];"
strsql = "Select " & strLat & " as lat, " & strLng & " as lng, '' as Phase, '' as Color, '' as Letter, '' as PopUpInfo into [" & strTempTableName & "];"
' Debug.Print strsql
dbs.Execute strsql _
, dbSeeChanges + dbFailOnError
dbs.Execute "Delete * from [" & strTempTableName & "];"
End If
'* Update the temp table
Marker = 19
'* v1.2
'strSQL = "Insert into [" & strTempTableName & "] " & _
"(lat, lng, Location, Color, Letter, PopUpInfo) " & _
"values " & _
"(" & dblLat & ", " & dblLng & ", " & Chr(34) & strLocation & Chr(34) & ",'" & strColor & "', '" & strLetter & "', " & Chr(34) & strPopUpInfo & Chr(34) & ");"
strsql = "Insert into [" & strTempTableName & "] " & _
"(lat, lng, Phase, Color, Letter, PopUpInfo) " & _
"values " & _
"(" & strLat & ", " & strLng & ", " & Chr(34) & strPhase & Chr(34) & ",'" & strColor & "', '" & strLetter & "', " & Chr(34) & strPopUpInfo & Chr(34) & ");"
'Debug.Print strSQL
'Stop
Marker = 20
dbs.Execute strsql _
, dbSeeChanges + dbFailOnError
Marker = 21
rst.movenext
Loop
'* output the temp table to a .csv file in the folder where the data back-end resides
Marker = 22
'strOutputFileName = "MapPoints2.csv"
FoundIt = False
For Each tdf In dbs.TableDefs
If Trim("" & tdf.Connect) = "" Then
Else
'pddxxx fix bug.
'If Left(tdf.Connect, Len(";Database=") = ";Database=") Then
If Left(tdf.Connect, Len(";Database=")) = ";Database=" Then
FoundIt = True
Exit For
End If
End If
Next tdf
If FoundIt Then
Marker = 23
'* Found folder where application back-end resides
strExistingTableName = tdf.Name
strFolder = dbs.TableDefs(strExistingTableName).Connect
strFolder = Replace(strFolder, ";Database=", "")
strFolder = xg_GetFolderFromFilename(strFolder)
Else
Marker = 24
'* Could not find an application back-end table. Use location of application front-end
strFolder = xg_GetFolderFromFilename(dbs.Name)
End If
'* Hard-code the location of the Multi-Location Mapper folder here, if needed
'strFolder = "C:\MyFolder\MySubfolder"
Marker = 25
If Dir(strFolder & "mlm*.*") = "" Then
MsgBox "The Multi-Location Mapper library could not be found", , "Multi-Location Mapper"
GoTo Exit_Section
End If
'* Remove any trailing "\"'s, if they exist.
For i = 1 To 2
If Right(strFolder, 1) = "\" Then
strFolder = Left(strFolder, Len(strFolder) - 1)
End If
Next i
Marker = 26
'* Output the data to csv file
'* v1.2
'DoCmd.TransferText acExportDelim, , strTempTableName, strFolder & "\" & strOutputFileName
strOutputFileName = "MapPoints2.xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, strTempTableName, strFolder & "\" & strOutputFileName, False
'* Call mapper
Marker = 27
'* Changed this section to use Shell for access runtime compatibility
If SysCmd(acSysCmdRuntime) Then
Shell "cmd /c " & Chr(34) & strFolder & "\" & "mlm2000.mdb" & Chr(34), vbHide
Else
Dim accapp As Access.Application
Marker = 28
Set accapp = New Access.Application
Marker = 29
accapp.OpenCurrentDatabase (strFolder & "\" & "mlm2000.mdb")
Marker = 30
accapp.Visible = True
End If
Marker = 99
Exit_Section:
On Error Resume Next
Set dbs = Nothing
Set rst = Nothing
Set qdf = Nothing
Set tdf = Nothing
fMLMMapIt = Rtn
On Error GoTo 0
Exit Function
Err_Section:
Select Case Err
Case Else
Beep
MsgBox "Error in fMLMMapIt (" & Marker & "), object " & Err.Source & ": " & Err.Number & " - " & Err.Description
End Select
Err.Clear
Resume Exit_Section
End Function
thanks