P
Paul
I'm trying to run the following code which is intended to append records
into a one field table. For the source of the records, I'm looping through
folders in a specified directory in our network, and I'm trying to append
the names of those folders into records in that table.
I have a syntax error in the following line:
strSQL = "INSERT INTO tblStreetAddress ( StreetAddress ) SELECT " & MyName
& ";"
because the procedure produces the error message on the following line:
db.Execute strSQL
How can I modify that assignment statement above to avoid the error?
Here is the complete procedure:
Private Sub fill_StreetAddress()
On Error GoTo HandleErr
Dim db As Database
Dim MyName As String
Dim strPath As String
Dim strSQL As String
Set db = CurrentDb
strPath = "M:\\Jobs\Agency\City\"
MyName = Dir(strPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(strPath & MyName) And vbDirectory) = vbDirectory Then
'Debug.Print MyName ' Display directories only
strSQL = "INSERT INTO tblStreetAddress ( StreetAddress ) SELECT
" & MyName & ";"
db.Execute strSQL
End If
End If
MyName = Dir ' Get next entry.
Loop
ExitHere:
On Error Resume Next
'rs.Close
Exit Sub
HandleErr:
Select Case Err
Case Else
MsgBox Err & ": " & Err.Description, , _
"Sub fill_StreetAddress"
End Select
Resume ExitHere
End Sub
Thanks in advance,
Paul
into a one field table. For the source of the records, I'm looping through
folders in a specified directory in our network, and I'm trying to append
the names of those folders into records in that table.
I have a syntax error in the following line:
strSQL = "INSERT INTO tblStreetAddress ( StreetAddress ) SELECT " & MyName
& ";"
because the procedure produces the error message on the following line:
db.Execute strSQL
How can I modify that assignment statement above to avoid the error?
Here is the complete procedure:
Private Sub fill_StreetAddress()
On Error GoTo HandleErr
Dim db As Database
Dim MyName As String
Dim strPath As String
Dim strSQL As String
Set db = CurrentDb
strPath = "M:\\Jobs\Agency\City\"
MyName = Dir(strPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(strPath & MyName) And vbDirectory) = vbDirectory Then
'Debug.Print MyName ' Display directories only
strSQL = "INSERT INTO tblStreetAddress ( StreetAddress ) SELECT
" & MyName & ";"
db.Execute strSQL
End If
End If
MyName = Dir ' Get next entry.
Loop
ExitHere:
On Error Resume Next
'rs.Close
Exit Sub
HandleErr:
Select Case Err
Case Else
MsgBox Err & ": " & Err.Description, , _
"Sub fill_StreetAddress"
End Select
Resume ExitHere
End Sub
Thanks in advance,
Paul