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 "You chose a different extension!"
End If
ExitHere:
Set cdl = Nothing
Exit Sub
HandleErrors:
Select Case Err.Number
Case cdlCancel
' Cancelled!
Resume ExitHere
Case Else
MsgBox "Error: " & Err.Description & _
"(" & Err.Number & "
"
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 "#" from the hyperlink.
x.pFrom = Mid(StrFile, 2, Len(StrFile) - 2)
'Pastes the file to stated location.
x.pTo = "k:\"
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 "#" from the hyperlink.
x.pFrom = Mid(StrFile2, 2, Len(StrFile2) - 2)
'Pastes the file to stated location.
x.pTo = "k:\"
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 "#" from the hyperlink.
x.pFrom = Mid(StrFile3, 2, Len(StrFile3) - 2)
'Pastes the file to stated location.
x.pTo = "k:\"
'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 "#" from the hyperlink.
x.pFrom = Mid(StrFile4, 2, Len(StrFile4) - 2)
'Pastes the file to stated location.
x.pTo = "k:\"
'x.fFlags = FOF_NOCONFIRMATION
x.wFunc = FO_COPY
SHFileOperation x
MsgBox "Copy Complete.", vbOKOnly
End Sub
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 "You chose a different extension!"
End If
ExitHere:
Set cdl = Nothing
Exit Sub
HandleErrors:
Select Case Err.Number
Case cdlCancel
' Cancelled!
Resume ExitHere
Case Else
MsgBox "Error: " & Err.Description & _
"(" & Err.Number & "
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 "#" from the hyperlink.
x.pFrom = Mid(StrFile, 2, Len(StrFile) - 2)
'Pastes the file to stated location.
x.pTo = "k:\"
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 "#" from the hyperlink.
x.pFrom = Mid(StrFile2, 2, Len(StrFile2) - 2)
'Pastes the file to stated location.
x.pTo = "k:\"
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 "#" from the hyperlink.
x.pFrom = Mid(StrFile3, 2, Len(StrFile3) - 2)
'Pastes the file to stated location.
x.pTo = "k:\"
'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 "#" from the hyperlink.
x.pFrom = Mid(StrFile4, 2, Len(StrFile4) - 2)
'Pastes the file to stated location.
x.pTo = "k:\"
'x.fFlags = FOF_NOCONFIRMATION
x.wFunc = FO_COPY
SHFileOperation x
MsgBox "Copy Complete.", vbOKOnly
End Sub