MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




Advice Please... Access Code works but could be improved

This is a discussion on Advice Please... Access Code works but could be improved within the MapPoint 2006/2009 Discussion forums, part of the Map Forums category; Hi all Looking for some help with this problem. I have a database with five tables. The master table has ...


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-22-2006
Junior Member
White Belt
 
Join Date: Mar 2005
Posts: 9
Advice Please... Access Code works but could be improved

Hi all

Looking for some help with this problem.

I have a database with five tables. The master table has all of the reps from different companies. There are a further four tables with the customers from these different companies (makes sense to the database (honest!! )).

I have all of the Reps and customers locations from their eastings and northings (UK). I designed a simple search form where the company, area and rep codes can be selected which displays the location of the Rep on a map. Really easy so far.

Things went a bit off when I then decided to try and plot all of the customers for that particular rep on the same map. Should have been easy enough as I already had the company and rep codes from the Access Form and it should just have been a simple case of passing these variables to a query in the database.

This simple problem kept throwing up "Unable to connect to Database" errors (even though it was the self same database that I had open that I was trying to query). The only way that I could do it was to create a temporary table, set and plot the dataset from that then delete the temporary table.

The following code works but sometimes throws up the same error ("Unable to connect...").

Code:
Dim db As Database
Dim custcount As Long
Dim stTbl, stCoTbl, stTempTbl, stCrit, stSQL, stQry As String
    
Set db = CurrentDb()

    stTbl = "CustTbl" & Me.Co & " OS"
    stCrit = "[Area] = " & Me.Area & " AND [Rep_ID] = " & Me.Rep 
    custcount = DCount("[Cust_ID]", stTbl, stCrit) 

    Me.OSGrid = DLookup("[Easting]", "LocTbl", "([Co] = [Forms]![SrchFrm]![Co]) AND ([Area] = [Forms]![SrchFrm]![Area]) AND ([Rep] = [Forms]![SrchFrm]![Rep])") & " " & DLookup("[Northing]", "LocTbl", "([Co] = [Forms]![SrchFrm]![Co]) AND ([Area] = [Forms]![SrchFrm]![Area]) AND ([Rep] = [Forms]![SrchFrm]![Rep])")
    Me.OSGrid.Visible = True
    Me.Customers = custcount & " Customers"
    Me.Customers.Visible = True

    Dim oMpApp As New MapPoint.Application
    Dim oDS As MapPoint.DataSet
    Dim RepLoc, RepPin As Object

    stCoTbl = Me.Co & "-" & Me.Area & "-" & Me.Rep
    stSQL = "SELECT [Easting] & "" "" & [Northing] AS [OS Grid Reference] INTO [" & stCoTbl & "]" _
        & "FROM [" & stTbl & "] " _
        & "WHERE ((([" & stTbl & "].Area)=" & Me.Area & ") AND (([" & stTbl & "].Rep_ID)=" & Me.Rep & "));" 
    DoCmd.RunSQL stSQL
    Set RepLoc = oMpApp.ActiveMap.LocationFromOSGridReference(OSGrid, 25)
    Set RepPin = oMpApp.ActiveMap.AddPushpin(RepLoc)
    With oMpApp.ActiveMap.DataSets
        stTempTbl = db.Name & "!" & stCoTbl
        Set oDS = .ImportData(stTempTbl, , geoCountryUnitedKingdom, , geoImportAccessTable)
        oDS.ZoomTo
    End With
    RepPin.Symbol = 60
    oDS.Symbol = 20
    RepPin.highlight = True
    oMpApp.Visible = True
    oMpApp.UserControl = True
    DoCmd.DeleteObject acTable, stCoTbl

End Sub
I would be VERY grateful for any suggestions to improve this as I feel it is a rather clunky and slow solution to what would appear to be a fairly simple problem of passing variables to an Access Query.

Thanks in advance

Iain T.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 06-24-2006
Junior Member
Yellow Belt
 
Join Date: Apr 2006
Posts: 20
Would it be possible to zip up a subset of the data along with your project? I'll take a look at it if you can. If you don't feel comfortable with that, it's understandable.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 06-26-2006
Junior Member
White Belt
 
Join Date: Mar 2005
Posts: 9
Thanks for the reply...

Will prepare an anonymised dataset - save the boss going mental about data protection

I'll get back to you as soon as poss..

Cheers

I.T.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 01-04-2008
Junior Member
White Belt
 
Join Date: Jan 2008
Posts: 6
Re: Advice Please... Access Code works but could be improved

Hello I.T.,

I've read your post looking for a solution of the same problem. Unfortunately the discussion did not progress further. Did you find a clue?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 01-08-2008
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,055
Re: Advice Please... Access Code works but could be improved

Hi,

As far as I can see quick on the original post is that he try to connect mappoint to some dataset. but mappoint has his own datasets and every dataset is different, so you cannot just connect to something else. you have to populate it looping through the records.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 01-09-2008
Junior Member
White Belt
 
Join Date: Jan 2008
Posts: 6
Re: Advice Please... Access Code works but could be improved

Hello Wilfried,

thanx for your reply.

My problem with using ImportData from an Access Table from the currently used database, is the error "unable to connect to database".

I thought it to be a problem before even trying to import Data into the MapPoint Datasets.
Perhabs there's a problem with my declaration part??

I posted my code just below, perhabs it is easy to see.

Quote:
Public Function Georef()

Dim KH As Object
Dim db As Database
Dim cn As ADODB.Connection
Dim objApp As New MapPoint.Application
Dim objMap As MapPoint.Map
Dim objDataSet As MapPoint.DataSet
Dim objPat As MapPoint.DataSet 'Patientenverteilung
Dim objShp As MapPoint.Shape
Dim objLoc As MapPoint.Location
Dim objAdj As MapPoint.Adjustments
Dim objField As MapPoint.Field
Dim Adresse, DSM As String
Dim objRecordset As MapPoint.Recordset
Dim objSym As MapPoint.Symbol
Dim ImportArray(1, 1)
Dim Pfad As String

On Error GoTo GeorefError

'reading Data for georeference
Set db = CurrentDb
Set KH = db.OpenRecordset("KH-Daten", dbOpenDynaset)
KH.MoveFirst
objApp.Visible = True
objApp.UserControl = True
Set objMap = objApp.ActiveMap
Adresse = KH![KH-Strasse] & "+" & Str(KH![KH-PLZ]) & "+" & KH![KH-Ort]
Set objLoc = objMap.FindAddressResults(KH![KH-Strasse], KH![KH-Ort], , , Str(KH![KH-PLZ]), geoCountryGermany)(1)
objApp.ActiveMap.AddPushpin objLoc, KH![KH-Name]
objApp.ActiveMap.DataSets(1).Name = KH![KH-Name]
objApp.ActiveMap.DataSets(1).Symbol = 298
objApp.ActiveMap.DataSets.ZoomTo

'initialising Importarray
ImportArray(0, 0) = "PLZ"
ImportArray(1, 0) = "Anzahl"
ImportArray(1, 1) = geoFieldInformation

'Set cn = New ADODB.Connection
'cn.Open (CurrentProject.Connection)

Pfad = db.Name & "\MAA_LS.mdb!maa_Patientenherkunft"
Set objPat = objApp.ActiveMap.DataSets.ImportData(Pfad, ImportArray, geoCountryGermany, 0, geoImportAccessTable)


objApp.ActiveMap.Saved = -1 'MapPoint fragt nicht nach speichern der Karte

Exit Function

GeorefError:
MsgBox Err.Description, vbCritical, "Fehler"
End Function
Thanx for your help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 01-10-2008
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,055
Re: Advice Please... Access Code works but could be improved

Hi,

Code:
ImportArray(0, 0) = "PLZ"
ImportArray(1, 0) = "Anzahl"
ImportArray(1, 1) = geoFieldInformation
Should you not specify witch fields are latitude and longitude ?

Code:
Pfad = db.Name & "\MAA_LS.mdb!maa_Patientenherkunft"
Set objPat = objApp.ActiveMap.DataSets.ImportData(Pfad, ImportArray, geoCountryGermany, 0, geoImportAccessTable)
Did you also try geoImportAccessQuery ?

Sorry don't have more idea's at the moment...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8 (permalink)  
Old 01-11-2008
Junior Member
White Belt
 
Join Date: Jan 2008
Posts: 6
Re: Advice Please... Access Code works but could be improved

Hello Wilfried,

thanx for your reply. I'm a real rookie in programming MapPoint with VBA and therefore happy about every advice.

As far as I understood it, latitude and longitude are only two items of the dataset object you may "organise" in an importarray - just as geofieldinformation is one.

For I want to import data from an access table, I did't try the query method. The program application flow makes the query run seperately, which should remain this way.

Wouldn't this cause an error concerning the data types instead of unability of connecting to the database?

Thank you, this far....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9 (permalink)  
Old 01-16-2008
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,055
Re: Advice Please... Access Code works but could be improved

Hi,

I think you have to specify which field is latitude and which one is longitude. Something like this (C#):

Code:
object[,] fieldSpecifications = null;
fieldSpecifications = new object[2, 2];
//Specify what fields are geographic and what fields are not
fieldSpecifications[0, 0] = "Lat";
fieldSpecifications[0, 1] = MapPoint.GeoFieldType.geoFieldLatitude;
fieldSpecifications[1, 0] = "Lon";
fieldSpecifications[1, 1] = MapPoint.GeoFieldType.geoFieldLongitude;
dataSet = MP.ActiveMap.DataSets.ImportData(fileName, 
				       fieldSpecifications, 
				       MapPoint.GeoCountry.geoCountryDefault,
				       MapPoint.GeoDelimiter.geoDelimiterSemicolon, 0);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10 (permalink)  
Old 01-20-2008
Junior Member
White Belt
 
Join Date: Jan 2008
Posts: 6
Re: Advice Please... Access Code works but could be improved

Hi Wilfried,

just to complete this question...I found the mistake.

I mixed the DAO and ADODB connections to the database and so the data could not be imported.

You don't have to record the latitude and longitude of a dataset, but may also just record postal code or adress.

If anyone has the same problem, here is my code that works:
Quote:
Public Function Georef()
Dim cn As ADODB.Connection
Dim KH As ADODB.Recordset
Dim objApp As New MapPoint.Application
Dim objMap As MapPoint.Map
Dim objDataSet As MapPoint.DataSet
Dim objPat As MapPoint.DataSet 'Patientenverteilung
Dim objShp As MapPoint.Shape
Dim objLoc As MapPoint.Location
Dim objAdj As MapPoint.Adjustments
Dim objField As MapPoint.Field
Dim Adresse, DSM As String
Dim objRecordset As MapPoint.Recordset
Dim objSym As MapPoint.Symbol
Dim ImportArray(1, 1)
Dim Pfad As String
On Error GoTo GeorefError

'reading Data for georeference

Set KH = New ADODB.Recordset
Set cn = CurrentProject.AccessConnection
KH.Open "select * from [KH-Daten]", cn
KH.MoveFirst
objApp.Visible = True
objApp.UserControl = True
Set objMap = objApp.ActiveMap
Adresse = KH![KH-Strasse] & "+" & Str(KH![KH-PLZ]) & "+" & KH![KH-Ort]
Set objLoc = objMap.FindAddressResults(KH![KH-Strasse], KH![KH-Ort], , , Str(KH![KH-PLZ]), geoCountryGermany)(1)
objApp.ActiveMap.AddPushpin objLoc, KH![KH-Name]
objApp.ActiveMap.DataSets(1).Name = KH![KH-Name]
objApp.ActiveMap.DataSets(1).Symbol = 298
objApp.ActiveMap.DataSets.ZoomTo

'initialising Importarray
ImportArray(0, 0) = "PLZ"
ImportArray(1, 0) = "Anzahl"
ImportArray(1, 1) = geoFieldInformation

Pfad = CurrentProject.Path & "\MAA_LS.mdb!maa_Patientenherkunft"
Set objPat = objApp.ActiveMap.DataSets.ImportData(Pfad, ImportArray, geoCountryGermany, 0, geoImportAccessTable)
objApp.ActiveMap.Saved = -1 'MapPoint fragt nicht nach speichern der Karte

Exit Function

GeorefError:
MsgBox Err.Description, vbCritical, "Fehler"
End Function
Wilfried, thanx again for your help. See you again in MP2K.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
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
Pushpin software advice please nsundby MapPoint 2006/2009 Discussion 6 06-30-2005 04:38 AM
New to MapPoint, Advice on this solution . . . Anonymous MapPoint 2006/2009 Discussion 0 02-04-2004 07:49 AM
Could someone explain how item() works on shapes collection? spideybud MapPoint 2006/2009 Discussion 0 12-15-2003 02:02 PM
to import data of one access file into another using vb code bushi_khan MapPoint 2006/2009 Discussion 0 10-14-2003 02:12 AM
VBA Access 2002 Code Help Needed rkehn MapPoint 2006/2009 Discussion 0 01-26-2003 01:23 PM


All times are GMT -5. The time now is 02:17 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
MP2K Magazine
Visitor Map

Cheap flights to Greece
Check Holiday Hypermarket for the latest cheap flights to Greece. Save your money for memorable souvenirs. See online today!

Portugal Holidays
Find and book Portugal Holidays with Travel Counsellors. Holiday destinations around the world including Portugal.

Holidays Italy
Book your holidays in Italy. Italy has a great climate and the beaches to go with it. Book a great deal for great value online at dealchecker.co.uk.

Antigua Holidays
We have the most popular Antigua holidays at highly competitive prices at The Holiday Place. Book a break in sunny Antigua today.

Cheap Greece Holidays
For cheap Greece holidays make sure you know when to book and who to book with. Visit ulookubook.com to get help with doing both of those things. Why not time your visit with a Greek festival?

Holidays
At Travel.co.uk the options for holidays are endless. Do some online comparison shopping!

Holidays to Cyprus
Take the plunge into a world of summer splendour! Find information on holidays to Cyprus online, only at On The Beach.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51