I am using the CommonDialog and it selects my file fine but if you go to another text box on the form and type some information and happen to hit enter it pulls up the Showopen again? How do I get it to stop doing this?
Printable View
I am using the CommonDialog and it selects my file fine but if you go to another text box on the form and type some information and happen to hit enter it pulls up the Showopen again? How do I get it to stop doing this?
you must have Focus set to your command button
Posting your code would help one to see what is happening.
Are you saying that I can just set the Command1 button to lostfocus?Code:Private Sub Command1_Click()
If Check2 = 0 Then
' Set CancelError is True
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
' Set flags
CommonDialog1.Flags = cdlOFNExplorer Or cdlOFNHideReadOnly
' Set filters
CommonDialog1.Filter = "All Files (*.*)|*.*|Text Files" & _
"(*.txt)|*.txt|Batch Files (*.bat)|*.bat"
' Specify default filter
CommonDialog1.FilterIndex = 1
' Display the Open dialog box
CommonDialog1.ShowOpen
' Display name of selected file
UploadFile = CommonDialog1.FileName
Exit Sub
Else
Dim strResFolder As String
strResFolder = BrowseForFolder(hWnd, "Please select a folder.")
If strResFolder = "" Then
Call MsgBox("The Cancel button was pressed.", vbExclamation)
Else
UploadFile = strResFolder
End If
CommonDialog1.
ErrHandler:
'User pressed the Cancel button
Exit Sub
End If
End Sub
Perhaps your default focus is the commandbutton
Ie...if Command1.Default = True then whenever you hit enter you will activate the code in the button.
Put this in your form load event and try it.
Command1.Default = False
Thank you the Command1 button was set to the Default--you guys are good.