PDA

View Full Version : Back to user form



kamalmalek
06-16-2012, 08:40 PM
Dear Supporters,

i have a form "with textbox"
i put Msgbox if user dose not enter his name in text box as follow:

dim i as string
i = TextBox1

If i = "" Then
MsgBox ("Please Enter your Name ")
Else
'my opreation
end if
the porblem is " when user dose not enter his name msgbox still appear continously and dose not give chance for user to re-try using form"

i need to show msgbox and let user re-enter his name in textbox1

please help
and thanks in advance

fcarboni
06-17-2012, 01:55 AM
Hi,
into your code missing condition to do..
like
private sub cmd1_click()
Dim i As String
i = TextBox1
If i = "" Then
MsgBox ("Please Enter your Name ")
Else
MsgBox "Welcome " & i
End If
end sub

kamalmalek
06-17-2012, 05:36 AM
dear Fcarboni,
even we put code y mentioned:

private sub cmd1_click()
Dim i As String
i = TextBox1
If i = "" Then
MsgBox ("Please Enter your Name ")
Else
MsgBox "Welcome " & i
End If
end sub

and user dose not enter his name in textbox1 no chance to user to re-enter
his name,
i need when msgbox is appear "please enter your name" then user press 'ok' return back to user form
not loop like here!
regards

fcarboni
06-17-2012, 11:45 PM
Ciao kamalmalek,
wath you've to do?
I don't understand wath you want.
You need know the user name to able or disable open file?? complie form?? or more??
Think wath you want, and if you want to try some think you can try this symple code:
Private Sub Workbook_Open()
Dim Ask01 As String
Dim Ask02 As String
Ask01 = InputBox("Please insert your name", "My file, user identification")
If (Ask01 <> Empty) Then
MsgBox "Welcome " & Ask01
Else
Ask02 = InputBox("2th time to insert your name, if youdon't insert this file will be closed", "My file, user identification")
If (Ask02 <> Empty) Then
MsgBox "Welcome " & Ask02
Else
ActiveWorkbook.Close False

End If
End If
End Sub
have a nice day
Fabrizio

CodeNinja
06-18-2012, 08:22 AM
Kamalmalek,
I think you are not getting the information into the variable i

You can validate this by breaking the run and checking in the immediate window. I think the line i = TextBox1 should read more like:
i = [userFormName].TextBox1.Text or:
i = UserForm1.TextBox1.Text

lncrj017
06-18-2012, 11:35 PM
Private Sub cmd1_click()
Dim i As String
i = TextBox1.value
If i = "" Then
MsgBox ("Please Enter your Name ")
userform.show'put your userform name change "userform"
Else
MsgBox "Welcome " & i
End If
End Sub