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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Msgbox action

Status
Not open for further replies.

razchip

Technical User
Feb 2, 2001
133
US
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
 
How about

If MsgBox (.FileName, vbOKCancel, "Import Bakery Mfg Recipes") = vbOK Then
 
...
Dim intReply As Integer
...
intReply = MsgBox .FileName, vbOKCancel, "Import Bakery Mfg Recipes"
If intReply = vbOK Then
...


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
The MsgBox should be called somewhat differently...

dim intReply as integer

intReply = MsgBox( .FileName, vbOKCancel, "Import Bakery Mfg Recipes)

if intReply = vbOk then
...
End if
 
Thanks for the help, got it to work.

Thanks for the help.
Greg
 
A thought

dim msg as string
msg = msgbox ("message",vbokcancel)
if msg = vbcancel then exit sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top