I'm having a problem getting if then statement to work for a vbOKCancel message box. No matter which button I click, the function continues to process. I've tried various combinations, but have not gotten it to work. This is what I currently have.
Private Sub cmdOK_Click()
Dim dlg As New CommonDialog
Dim strFile As String
Dim strSQL As String
With dlg
.FileName = "*.txt"
.InitDir = "\\Scott\Rnet\RnetDat\Pic\600-649\614"
.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
.Flags = cdlHideReadOnly Or cdlFileMustExist Or cdlPathMustExist
If .OpenDialog() = True Then
MsgBox .FileName, vbOKCancel, "Import Bakery Mfg Recipes"
If vbOKCancel = vbOK Then
' Extract only the file name
'strFile = Mid(strFile, InStrRev(strFile, "\") + 1)
strFile = Right(.FileName, 24)
strSQL = "INSERT INTO ImportHistory (ImpFileName) VALUES( " & Chr(34) & strFile & Chr(34) & " )"
'Clear old data & Import Data
DoCmd.SetWarnings False
DoCmd.OpenQuery "qry 3 del Pic614 Import", acViewNormal, acEdit
DoCmd.TransferText acImportDelim, "PIC614 Import Specification", "Pic614Import", "\\Scott\Rnet\RnetDat\Pic\600-649\614\" & strFile, False, ""
'If Cancel button is selected
Else
MsgBox "No data will be imported", vbOKOnly, "Incorrect file selection"
End If
Else
MsgBox "No file selected", vbInformation
End If
End With
Set dlg = Nothing
End Sub
I hate to bother you with such a small matter, but it's driving me nuts. Thanks.
Thanks for the help.
Greg
Private Sub cmdOK_Click()
Dim dlg As New CommonDialog
Dim strFile As String
Dim strSQL As String
With dlg
.FileName = "*.txt"
.InitDir = "\\Scott\Rnet\RnetDat\Pic\600-649\614"
.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
.Flags = cdlHideReadOnly Or cdlFileMustExist Or cdlPathMustExist
If .OpenDialog() = True Then
MsgBox .FileName, vbOKCancel, "Import Bakery Mfg Recipes"
If vbOKCancel = vbOK Then
' Extract only the file name
'strFile = Mid(strFile, InStrRev(strFile, "\") + 1)
strFile = Right(.FileName, 24)
strSQL = "INSERT INTO ImportHistory (ImpFileName) VALUES( " & Chr(34) & strFile & Chr(34) & " )"
'Clear old data & Import Data
DoCmd.SetWarnings False
DoCmd.OpenQuery "qry 3 del Pic614 Import", acViewNormal, acEdit
DoCmd.TransferText acImportDelim, "PIC614 Import Specification", "Pic614Import", "\\Scott\Rnet\RnetDat\Pic\600-649\614\" & strFile, False, ""
'If Cancel button is selected
Else
MsgBox "No data will be imported", vbOKOnly, "Incorrect file selection"
End If
Else
MsgBox "No file selected", vbInformation
End If
End With
Set dlg = Nothing
End Sub
I hate to bother you with such a small matter, but it's driving me nuts. Thanks.
Thanks for the help.
Greg