Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi CopyMoveFiles Coding get stuck on Null value 1

Status
Not open for further replies.

BubbaJean

IS-IT--Management
Jun 5, 2002
111
0
0
US
Again, with the help of many of you, I'm able to copy files from one dir C;/ to another dir K:/.
But if any of the fields are empty, the code stops and goes into debug mode and I'm unable to get the code to handle a null field
The only field required is DS_X1 the rest of the fields
DS_X2
DS_X3
DS_X4
are nice to have but maybe left empty
Can someone help me with the code below to continue to run if
DS_X2=Null
or
DS_X3=Null
or
DS_X4=Null

Thanks in advance

Option Compare Database

Private Const FO_COPY = &H2

Private Const FOF_SIMPLEPROGRESS = &H100

Private Const FOF_NOCONFIRMATION = &H10

Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) As Long

Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Boolean
hNameMappings As Long
lpszProgressTitle As String
End Type

Private Sub cmdFileOpen_Click()

' Test the CommonDlg class' FileOpen common dialog.

Dim cdl As CommonDlg
Set cdl = New CommonDlg

cdl.hWndOwner = Me.hWnd
cdl.CancelError = True

On Error GoTo HandleErrors

' Set three pairs of values for the Filter.
cdl.Filter = _
"Adobe Acrobat Document (*.pdf)|" & _
"*.pdf|" & _
"Database files (*.mdb, *.mde, *.mda)|" & _
"*.mdb;*.mde;*.mda|" & _
"All files (*.*)|" & _
"*.*"

' Select filter 1 (DataSheet files) when
' the dialog opens.
cdl.FilterIndex = 1

' Indicate that you want to use a callback function,
' change back to the original directory when
' you're done, and require that the selected
' file actually exist.
cdl.OpenFlags = cdlOFNEnableHook Or _
cdlOFNNoChangeDir Or cdlOFNFileMustExist

' Select the callback function.
cdl.CallBack = adhFnPtrToLong(AddressOf GFNCallback)

' Set up miscellaneous properties.
cdl.InitDir = "C:\"
cdl.FileName = "autoexec.pdf"
cdl.DefaultExt = "pdf"

' Open the file open dialog box,
' and wait for it to be dismissed.
cdl.ShowOpen

' Retrieve the selected file na
txtFileOpen = cdl.FileName

' Check the OpenFlags (or Flags) property to
' see if the selected extension is different than
' the default extension.
If (cdl.OpenFlags And _
cdlOFNExtensionDifferent) <> 0 Then
MsgBox &quot;You chose a different extension!&quot;
End If

ExitHere:
Set cdl = Nothing
Exit Sub

HandleErrors:
Select Case Err.Number
Case cdlCancel
' Cancelled!
Resume ExitHere
Case Else
MsgBox &quot;Error: &quot; & Err.Description & _
&quot;(&quot; & Err.Number & &quot;)&quot;
End Select
Resume ExitHere
End Sub

Private Sub cmdMoveFiles_Click()
'On Error GoTo ErrorX
Dim x As SHFILEOPSTRUCT
'***********DS_1X*************************
Dim StrFile As String
StrFile = Me.DS_X1.Value

'Copies the file in textbox DS_X1
'String function to get rid of the &quot;#&quot; from the hyperlink.
x.pFrom = Mid(StrFile, 2, Len(StrFile) - 2)
'Pastes the file to stated location.
x.pTo = &quot;k:\&quot;
x.fFlags = FOF_NOCONFIRMATION
x.wFunc = FO_COPY
SHFileOperation x


'***********DS_2X*************************

Dim StrFile2 As String
StrFile2 = Me.DS_X2.Value

'Copies the file in textbox DS_X2
'String function to get rid of the &quot;#&quot; from the hyperlink.
x.pFrom = Mid(StrFile2, 2, Len(StrFile2) - 2)

'Pastes the file to stated location.
x.pTo = &quot;k:\&quot;
x.fFlags = FOF_NOCONFIRMATION
x.wFunc = FO_COPY
SHFileOperation x


'***********DS_3X*************************
Dim StrFile3 As String
StrFile3 = Me.DS_X3.Value

'Copies the file in textbox DS_X3
'String function to get rid of the &quot;#&quot; from the hyperlink.
x.pFrom = Mid(StrFile3, 2, Len(StrFile3) - 2)
'Pastes the file to stated location.
x.pTo = &quot;k:\&quot;
'x.fFlags = FOF_NOCONFIRMATION
x.wFunc = FO_COPY
SHFileOperation x

'***********DS_4X*************************
Dim StrFile4 As String
StrFile4 = Me.DS_X4.Value

'Copies the file in textbox DS_X4
'String function to get rid of the &quot;#&quot; from the hyperlink.
x.pFrom = Mid(StrFile4, 2, Len(StrFile4) - 2)
'Pastes the file to stated location.
x.pTo = &quot;k:\&quot;
'x.fFlags = FOF_NOCONFIRMATION
x.wFunc = FO_COPY
SHFileOperation x
MsgBox &quot;Copy Complete.&quot;, vbOKOnly

End Sub

 
use something like the following:

Private Sub cmdMoveFiles_Click()
'On Error GoTo ErrorX
Dim x As SHFILEOPSTRUCT
'***********DS_1X*************************
Dim StrFile As String
StrFile = Me.DS_X1.Value
if isnull(strfile) = false then
'Copies the file in textbox DS_X1
'String function to get rid of the &quot;#&quot; from the hyperlink.
x.pFrom = Mid(StrFile, 2, Len(StrFile) - 2)
'Pastes the file to stated location.
x.pTo = &quot;k:\&quot;
x.fFlags = FOF_NOCONFIRMATION
x.wFunc = FO_COPY
SHFileOperation x

end if
'***********DS_2X*************************

Dim StrFile2 As String
StrFile2 = Me.DS_X2.Value
if isnull(strfile2) = false then
'Copies the file in textbox DS_X2
'String function to get rid of the &quot;#&quot; from the hyperlink.
x.pFrom = Mid(StrFile2, 2, Len(StrFile2) - 2)

'Pastes the file to stated location.
x.pTo = &quot;k:\&quot;
x.fFlags = FOF_NOCONFIRMATION
x.wFunc = FO_COPY
SHFileOperation x

end if
'***********DS_3X*************************
Dim StrFile3 As String
StrFile3 = Me.DS_X3.Value
if isnull(strfile3) = false then
'Copies the file in textbox DS_X3
'String function to get rid of the &quot;#&quot; from the hyperlink.
x.pFrom = Mid(StrFile3, 2, Len(StrFile3) - 2)
'Pastes the file to stated location.
x.pTo = &quot;k:\&quot;
'x.fFlags = FOF_NOCONFIRMATION
x.wFunc = FO_COPY
SHFileOperation x
end if
'***********DS_4X*************************
Dim StrFile4 As String
StrFile4 = Me.DS_X4.Value
if isnull(strfile4) = false then
'Copies the file in textbox DS_X4
'String function to get rid of the &quot;#&quot; from the hyperlink.
x.pFrom = Mid(StrFile4, 2, Len(StrFile4) - 2)
'Pastes the file to stated location.
x.pTo = &quot;k:\&quot;
'x.fFlags = FOF_NOCONFIRMATION
x.wFunc = FO_COPY
SHFileOperation x
MsgBox &quot;Copy Complete.&quot;, vbOKOnly
end if
End Sub


if the statement evaluates to true (meaning the value is null) then the code won't run and an error won't be produced.

let me know if you have problems
 
I ran the code but I got the following error message
&quot;Run-time Error '94'
Invaild use of Null
 
can you tell which line of code is highlighted when the program goes the to VB window?
 
If I leave DS_X2 field empty then click on
Move PDF Files
the Code highlites &quot;StrFile2 = Me.DS_X2.Value&quot;
Else
If I leave DS_X4 field empty then click on
Move PDF Files
the Code highlites &quot;StrFile2 = Me.DS_X4.Value&quot;

 
ok, no problem to fix at all. Here is the code you want to use instead then.

Private Sub cmdMoveFiles_Click()
'On Error GoTo ErrorX
Dim x As SHFILEOPSTRUCT
'***********DS_1X*************************
Dim StrFile As String
if isnull(me.ds_x1.value) = false then
StrFile = Me.DS_X1.Value

'Copies the file in textbox DS_X1
'String function to get rid of the &quot;#&quot; from the hyperlink.
x.pFrom = Mid(StrFile, 2, Len(StrFile) - 2)
'Pastes the file to stated location.
x.pTo = &quot;k:\&quot;
x.fFlags = FOF_NOCONFIRMATION
x.wFunc = FO_COPY
SHFileOperation x
end if

'***********DS_2X*************************

Dim StrFile2 As String
if isnull(me.ds_x2.value) = false then
StrFile2 = Me.DS_X2.Value

'Copies the file in textbox DS_X2
'String function to get rid of the &quot;#&quot; from the hyperlink.
x.pFrom = Mid(StrFile2, 2, Len(StrFile2) - 2)

'Pastes the file to stated location.
x.pTo = &quot;k:\&quot;
x.fFlags = FOF_NOCONFIRMATION
x.wFunc = FO_COPY
SHFileOperation x
end if

'***********DS_3X*************************
Dim StrFile3 As String
if isnull(me.ds_x3.value) = false then
StrFile3 = Me.DS_X3.Value

'Copies the file in textbox DS_X3
'String function to get rid of the &quot;#&quot; from the hyperlink.
x.pFrom = Mid(StrFile3, 2, Len(StrFile3) - 2)
'Pastes the file to stated location.
x.pTo = &quot;k:\&quot;
'x.fFlags = FOF_NOCONFIRMATION
x.wFunc = FO_COPY
SHFileOperation x
end if
'***********DS_4X*************************
Dim StrFile4 As String
if isnull(me.ds_x4.value) = false then
StrFile4 = Me.DS_X4.Value

'Copies the file in textbox DS_X4
'String function to get rid of the &quot;#&quot; from the hyperlink.
x.pFrom = Mid(StrFile4, 2, Len(StrFile4) - 2)
'Pastes the file to stated location.
x.pTo = &quot;k:\&quot;
'x.fFlags = FOF_NOCONFIRMATION
x.wFunc = FO_COPY
SHFileOperation x
MsgBox &quot;Copy Complete.&quot;, vbOKOnly
end if
End Sub

lemme know if it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top