Import Shapefile To Access DB (VBA)
Import Shapefile To Access DB (VBA)
sf As New MapWinGIS.Shapefile
tb As New MapWinGIS.Table
NewTable As TableDef
i As Long, x As Long
rs As DAO.Recordset
success As Boolean
delTable As Boolean
tblfields As Object
fldType As FieldType
NewTableName As String
f
fs As Object
oFileDialog As FileDialog
shpFileName As String
dbfFileName
'Selecting a File
Set fs = CreateObject("Scripting.FileSystemObject")
Set oFileDialog = Application.FileDialog(msoFileDialogFilePicker)
oFileDialog.Filters.Add "All files", "*.*" 'adding a filter for all-files
oFileDialog.Filters.Add "Shapefile", "*.shp", 1 'adding a filter for *.shp
oFileDialog.InitialFileName = Application.CurrentProject.Path 'start in the
actual folder
With oFileDialog
.Title = "Select Shapefile to load"
.ButtonName = "Select"
.AllowMultiSelect = False
If .Show = True Then
Dim vItem As Variant
For Each vItem In .SelectedItems
shpFileName = vItem 'this is the complete paht of the selected s
hapefile
Set f = fs.GetFile(vItem)
If Left(f.Type, 3) <> "SHP" Then 'checking filetype to assure it
s a shapefile (just very basic)
MsgBox "This seems to be no Shapefile!", vbExclamation, "Exi
ting!"
Exit Sub
End If
End Sub
Sub AppendDeleteField(tdfTemp As TableDef, _
strCommand As String, strName As String, _
Optional varType, Optional varSize)
'This code is taken out of the Microsoft Visual Basic Help!
With tdfTemp
' Check first to see if the TableDef object is
' updatable. If it isn't, control is passed back to
' the calling procedure.
If .Updatable = False Then
MsgBox "TableDef not Updatable! " & _
"Unable to complete task."
Exit Sub
End If
' Depending on the passed data, append or delete a
' field to the Fields collection of the specified
' TableDef object.
If strCommand = "APPEND" Then
.Fields.Append .CreateField(strName, _
varType, varSize)
Else
If strCommand = "DELETE" Then .Fields.Delete _
strName
End If
End With
End Sub