Here is my code, I have shortened it a bit.
Sub UploadDocDwgs()
Dim SQL As String
Dim SQL2 As String
Dim SQL3 As String
Dim SQL4 As String * 500
Dim rsFiles As New ADODB.Recordset
Dim MyImportFolder As String
Dim vFilePath As String
Dim vFileSize As Long
Dim vRevisionRef As String
Dim vNewPrimKey As String
Dim MyMessage As String
Dim vError As String
Dim FileName As String
Dim Confidential As Integer
Dim Counter As Integer
Dim DocOrDwg As Integer
On Error GoTo ErrorHandling
FileName = afGetOpenFileName(Me.hwnd, , "Select a file from the download
folder.")
If Nz(FileName, "") = "" Then Exit Sub
MyImportFolder = afGetBaseFilepath(FileName)
'MyImportFolder = InputBox("Input folder to import from", "Bulk Copy",
"c:\DocDwgImport")
DoCmd.Hourglass True
SQL = "SELECT * "
SQL = SQL & " FROM atbv_DocCtrl_BulkCopy WHERE CreatedBy = SUSER_SNAME()
ORDER BY DocDwgID"
rsFiles.Open SQL, CurrentProject.Connection, adOpenDynamic,
adLockOptimistic
If Nz(MyImportFolder) = "" Then
GoTo ExitMe
'Else
'MyImportFolder = MyImportFolder & "\"
End If
Counter = 0
While Not rsFiles.EOF
vFilePath = MyImportFolder & rsFiles("FileName")
If Nz(Dir(vFilePath, vbNormal)) = "" Then
MyMessage = MyMessage & rsFiles("FileName") & vbCrLf
End If
rsFiles.MoveNext
Wend
If Nz(MyMessage) <> "" Then
MsgBox "File(s) " & MyMessage & " was(were) not located in the
selected folder.", vbOKOnly, "File(s) Not Found"
GoTo ExitMe
End If
MyMessage = ""
rsFiles.MoveFirst
While Not rsFiles.EOF
If Nz(rsFiles("DocDwgID")) = "" Then
MyMessage = "Records exist that don't have a document ID. Those
records cannot be loaded."
GoTo ExitMe
End If
rsFiles.MoveNext
Wend
MyMessage = ""
rsFiles.MoveFirst
While Not rsFiles.EOF
'Check for Existing DocDwgID
If IsNull(afDLookup("[DocDwgID]", "atbv_DocCtrl_DocDwgs",
"[DocDwgID]='" & rsFiles("DocDwgID") & "'")) Then
MyMessage = MyMessage & "Inserted " & rsFiles("DocDwgID") &
" as New DocDwg ID" & vbCrLf
If Nz(rsFiles("ConfidentialityGroup"), "") = "" Then
Confidential = 0
Else
Confidential = 1
End If
If Nz(rsFiles("DocOrDwg"), "") = "DWG" Then
DocOrDwg = 0
Else
DocOrDwg = 1
End If
SQL = "INSERT INTO atbv_DocCtrl_DocDwgs (DocDwgID,
AltDocDwgID, Title, Originator, ContrCompany, CurrentRev, "
SQL = SQL & " CurrentRevDate, CurrentStep, EquipmentTagNo,
VendorPONo, "
SQL = SQL & " Facility, System, Discipline, DocType,
Confidential, ConfidentialityGroup, DocOrDwg)"
SQL = SQL & " SELECT '" & rsFiles("DocDwgID") & "', '" &
rsFiles("AltDocDwgID") & "',"
SQL = SQL & " '" & rsFiles("Title") & "', '" &
rsFiles("Originator") & "', '" & rsFiles("Company") & "', "
SQL = SQL & " '" & rsFiles("Rev") & "', "
SQL = SQL & " '" & afDate(rsFiles("RevDate")) & "', "
SQL = SQL & " LEFT('" & rsFiles("Step") & "',10), "
SQL = SQL & " '" & rsFiles("EquipmentNo") & "', "
SQL = SQL & " '" & rsFiles("PONo") & "', "
SQL = SQL & " '" & rsFiles("Facility") & "', "
SQL = SQL & " '" & rsFiles("System") & "', "
SQL = SQL & " '" & rsFiles("Discipline") & "', "
SQL = SQL & " '" & rsFiles("DocType") & "', "
SQL = SQL & " CAST(" & Confidential & "AS BIT), CAST(" &
DocOrDwg & "AS BIT), " & rsFiles("ConfidentialityGroup")
SQL = SQL & " CAST(" & DocOrDwg & "AS BIT)"
afExecute SQL, True, True
Else
MyMessage = MyMessage & "Updated " & rsFiles("DocDwgID") & "
DocDwg ID" & vbCrLf
SQL = "UPDATE atbv_DocCtrl_DocDwgs SET "
SQL = SQL & " Title = '" & rsFiles("Title") & "', "
SQL = SQL & " CurrentRev = '" & rsFiles("Rev") & "', "
SQL = SQL & " CurrentRevDate = '" &
afDate(rsFiles("RevDate")) & "', "
SQL = SQL & " CurrentStep = LEFT('" & rsFiles("Step") &
"',10), "
SQL = SQL & " IsDistributed = 0, RegulatoryStatus = 'Review'"
SQL = SQL & " DocOrDwg = " & DocOrDwg & " "
SQL = SQL & " WHERE DocDwgID = '" & rsFiles("DocDwgID") & "'"
afExecute SQL, True, True
End If
'Exit the Sub
ExitMe:
If rsFiles.State = adStateOpen Then rsFiles.Close
Set rsFiles = Nothing
DoCmd.Hourglass False
If Nz(MyMessage) = "" Then
MyMessage = "No files have been uploaded."
End If
MsgBox (MyMessage)
Exit Sub
'General error handling code
ErrorHandling:
Select Case Err
'--- Add Case statements for error between these lines ---
Case Else
If afErrorHandler = True Then
Resume 0
ElseIf afc("afTrapErr") Then
Stop
Resume 0
End If
End Select
Resume ExitMe
End Sub
Thanks In Advance For Any Feedback
Dirk Goldgar said:
The String data type in VBA is able to hold up to approximately 2 billion
characters, so I don't think that's the source of your problem. The Text
*field* type, in a table's design, is only able to hold 255 characters.
Could that be where your problem lies? If so, you can use the Memo type,
which is not so restricted.
Or it could be, I suppose, that you are managing to create a SQL statement
that is too long for the database engine to process. You'd need to post
your code so that we can see what's going on.
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)