john-86
03-13-2006, 05:10 AM
Hello all, here's part of the code I've been working on. I was wondering if someone would mind having a quick look over the code and tell me if there were any serious logic/syntax errors that needed to be addressed before I try it out.
I'd love to try and explain the project to you... but it's so very complex, it'd take me most of the day to type it out. Basically I want to import data from one table ("GIS Import Table") into two tables ("PN Name" & "PN Place/Feature"). The lettersNGR() function tests two values within the "GIS Import table" to return results to the "PN Place/Feature" table.
I'm thinking of making this a module so that it can be run by a macro. Are there any special considerations I have to make because of this?
Option Compare Database
Option Explicit
Public db As Database
Public nameRS As Recordset
Public featRS As Recordset
Public tempRS As Recordset
Set db = CurrentDb()
Set nameRS = db.OpenRecordset("PN Name", dbOpenTable)
Set featRS = db.OpenRecordset("PN Place/Feature", dbOpenTable)
Set tempRS = db.OpenRecordset("GIS Import Table", dbOpenTable)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Function lettersNGR()
Public eQualifier As Variant
Public nQualifier As Variant
Public letters As Variant
Dim east As Variant
Dim north As Variant
east = str (tempRS.Fields("Easting").Value) '''converts integer to string
north = str (tempRS.Fields("Northing").Value) '''converts integer to string
If ((east = "4?????") And (north = "10?????")) Then
letters = "HZ"
eQualifier = 400000
nQualifier = 1000000
ElseIf ((east = "4?????") And (north = "11?????")) Then
letters = "HU"
eQualifier = 400000
nQualifier = 1100000
ElseIf ((east = "4?????") And (north = "12?????")) Then
letters = "HP"
eQualifier = 400000
nQualifier = 1200000
ElseIf ((east = "3?????") And (north = "11?????")) Then
letters = "HT"
eQualifier = 300000
nQualifier = 1100000
End If
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''
Private Sub importFromGIS()
tempRS.MoveLast
tempRS.MoveFirst
While (Not tempRS.EOF)
lettersNGR '''call to function
nameRS.AddNew
featRS.AddNew
nameRS.Fields("Name Displayed As").Value = tempRS.Fields("featName").Value
featRS.Fields("NGR letters").Value = letters
featRS.Fields("NGR Easting").Value = (tempRS.Fields("Easting").Value - eQualifier)
featRS.Fields("NGR Northing").Value = (tempRS.Fields("Northing").Value - nQualifier)
nameRS.Update
featRS.Update
tempRS.MoveNext
Loop
End Sub
Thank you all very much for your help! When I learn to become a VBA expert I will sit on these forums, like you, trying to help wannabes like myself :)
Kind regards,
John
Me after a few weeks of VBA:
:wot - :dunno - :think: - :banghead: - :help
I'd love to try and explain the project to you... but it's so very complex, it'd take me most of the day to type it out. Basically I want to import data from one table ("GIS Import Table") into two tables ("PN Name" & "PN Place/Feature"). The lettersNGR() function tests two values within the "GIS Import table" to return results to the "PN Place/Feature" table.
I'm thinking of making this a module so that it can be run by a macro. Are there any special considerations I have to make because of this?
Option Compare Database
Option Explicit
Public db As Database
Public nameRS As Recordset
Public featRS As Recordset
Public tempRS As Recordset
Set db = CurrentDb()
Set nameRS = db.OpenRecordset("PN Name", dbOpenTable)
Set featRS = db.OpenRecordset("PN Place/Feature", dbOpenTable)
Set tempRS = db.OpenRecordset("GIS Import Table", dbOpenTable)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
Function lettersNGR()
Public eQualifier As Variant
Public nQualifier As Variant
Public letters As Variant
Dim east As Variant
Dim north As Variant
east = str (tempRS.Fields("Easting").Value) '''converts integer to string
north = str (tempRS.Fields("Northing").Value) '''converts integer to string
If ((east = "4?????") And (north = "10?????")) Then
letters = "HZ"
eQualifier = 400000
nQualifier = 1000000
ElseIf ((east = "4?????") And (north = "11?????")) Then
letters = "HU"
eQualifier = 400000
nQualifier = 1100000
ElseIf ((east = "4?????") And (north = "12?????")) Then
letters = "HP"
eQualifier = 400000
nQualifier = 1200000
ElseIf ((east = "3?????") And (north = "11?????")) Then
letters = "HT"
eQualifier = 300000
nQualifier = 1100000
End If
End Function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''
Private Sub importFromGIS()
tempRS.MoveLast
tempRS.MoveFirst
While (Not tempRS.EOF)
lettersNGR '''call to function
nameRS.AddNew
featRS.AddNew
nameRS.Fields("Name Displayed As").Value = tempRS.Fields("featName").Value
featRS.Fields("NGR letters").Value = letters
featRS.Fields("NGR Easting").Value = (tempRS.Fields("Easting").Value - eQualifier)
featRS.Fields("NGR Northing").Value = (tempRS.Fields("Northing").Value - nQualifier)
nameRS.Update
featRS.Update
tempRS.MoveNext
Loop
End Sub
Thank you all very much for your help! When I learn to become a VBA expert I will sit on these forums, like you, trying to help wannabes like myself :)
Kind regards,
John
Me after a few weeks of VBA:
:wot - :dunno - :think: - :banghead: - :help