Community of VE/MapPoint Users and Developers
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 ...
| |||||||
| Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| Advice Please... Access Code works but could be improved 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
Thanks in advance Iain T. |
| |||
| 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.
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| |||
| 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:
|
| |||
| Re: Advice Please... Access Code works but could be improved
Hi, Code: ImportArray(0, 0) = "PLZ" ImportArray(1, 0) = "Anzahl" ImportArray(1, 1) = geoFieldInformation Code: Pfad = db.Name & "\MAA_LS.mdb!maa_Patientenherkunft" Set objPat = objApp.ActiveMap.DataSets.ImportData(Pfad, ImportArray, geoCountryGermany, 0, geoImportAccessTable) Sorry don't have more idea's at the moment...
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| |||
| 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.... |
| |||
| 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);
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| |||
| 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:
|
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| 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 |
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.