Msg box error

GordonM

New Member
Joined
Jun 30, 2017
Messages
25
Hi guys,
need a little help on this one.

I have a userform its for a login page (Username and password) i have a few if and if not on it, but when i run the code it still gives me a message box (Wrong username) but only on the second user (Gordon) Im sure its something small.

Code:
If TextBox1 = "Gordon" And TextBox2 = "123" Then
Sheet1.Activate
Ufdairy.Show
End If
Unload UserForm2
If TextBox1 = "Collin" And TextBox2 = "1234" Then
Sheet1.Activate
Ufdairy.Show
End If
Unload UserForm2

If Not TextBox1 = ("Collin") Or TextBox1 = ("Gordon") Then
MsgBox ("Wrong User Name")
Exit Sub
End If


If Not TextBox2 = "1234" Or TextBox2 = "123" Then
MsgBox ("Wrong Password, Please Try Again")
Exit Sub
End If



End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Your if not textbox1 is kind of questionnable by the way you writed it.

VBA, and myself, don't know if you want to apply the "not" only for collin or gordon as well.

What is suggest you is use this.

Code:
[COLOR=#333333]If Not (TextBox1 = "Collin" Or TextBox1 = "Gordon") Then[/COLOR]


I thing it will solve your problem. If it does, you should make the same change for the password part.

Edit : if you want to modify your whole logic, I could help you if you want.
 
Last edited:
Upvote 0
can you help me with another one please?

i have another userform, from combobox1 i have a few textboxes that get data from a table with vlookup. i want to be able to change the data and send it back to the table to the same row.

I really new to this VBA.
 
Upvote 0
all i have is the userform and the table done.


Code:
Private Sub ComboBox1_dropbutt*******()
On Error Resume Next
With Me
.TextBox1 = Application.WorksheetFunction.VLookup((Me.ComboBox1), Sheet4.Range("table2"), 6, 0)
.TextBox2 = Application.WorksheetFunction.VLookup((Me.ComboBox1), Sheet4.Range("table2"), 7, 0)
.TextBox3 = Application.WorksheetFunction.VLookup((Me.ComboBox1), Sheet4.Range("table2"), 3, 0)
.TextBox4 = Application.WorksheetFunction.VLookup((Me.ComboBox1), Sheet4.Range("table2"), 9, 0)
.TextBox5 = Application.WorksheetFunction.VLookup((Me.ComboBox1), Sheet4.Range("table2"), 4, 0)
.ComboBox2 = Application.WorksheetFunction.VLookup((Me.ComboBox1), Sheet4.Range("table2"), 5, 0)
.ComboBox3 = Application.WorksheetFunction.VLookup((Me.ComboBox1), Sheet4.Range("table2"), 2, 0)
End With

End Sub

Private Sub CommandButton2_Click()
Unload vehicle_list

End Sub


Private Sub TextBox3_Change()
TextBox3 = Format(TextBox3.Text, "dd/mm/yyyy")
End Sub

Private Sub TextBox4_Change()
TextBox4 = Format(TextBox4.Value, "dd/mm/yyyy")
End Sub

Private Sub TextBox5_Change()
TextBox5 = Format(TextBox5.Value, "dd/mm/yyyy")
End Sub
 
Upvote 0
code:
[Private Sub ComboBox1_dropbutt*******()
On Error Resume Next
With Me
.TextBox1 = Application.WorksheetFunction.VLookup((Me.ComboBox1), Sheet4.Range("table2"), 6, 0)
.TextBox2 = Application.WorksheetFunction.VLookup((Me.ComboBox1), Sheet4.Range("table2"), 7, 0)
.TextBox3 = Application.WorksheetFunction.VLookup((Me.ComboBox1), Sheet4.Range("table2"), 3, 0)
.TextBox4 = Application.WorksheetFunction.VLookup((Me.ComboBox1), Sheet4.Range("table2"), 9, 0)
.TextBox5 = Application.WorksheetFunction.VLookup((Me.ComboBox1), Sheet4.Range("table2"), 4, 0)
.ComboBox2 = Application.WorksheetFunction.VLookup((Me.ComboBox1), Sheet4.Range("table2"), 5, 0)
.ComboBox3 = Application.WorksheetFunction.VLookup((Me.ComboBox1), Sheet4.Range("table2"), 2, 0)
End With

End Sub

Private Sub CommandButton2_Click()
Unload vehicle_list

End Sub


Private Sub TextBox3_Change()
TextBox3 = Format(TextBox3.Text, "dd/mm/yyyy")
End Sub

Private Sub TextBox4_Change()
TextBox4 = Format(TextBox4.Value, "dd/mm/yyyy")
End Sub

Private Sub TextBox5_Change()
TextBox5 = Format(TextBox5.Value, "dd/mm/yyyy")
End Sub]
 
Upvote 0
Hum, I understand perfectly that.

However, as it's a completely different problem, I would like you to start a new threat with that question and send m the link to it my private message so that I can answer on it.

I am going to write you some code about that in the same time.

This is mostly to help person that search for the same problem to have a better follow on all of this.

You seem to have issue at using code tags, when you put a tag at the start, you need to end it : [ CODE] [/CODE ]
 
Last edited:
Upvote 0
On another note, after watching more intensely your first code, I find some issue that could be problematic.

What you are currently doing is this :

If Gordon and 123, activate sheet 1 and show ufdairy. If not do nothing.
Close userform2
If Collin and 1234, activate sheet1 and show ufdairy. If not do nothing.
Close userform2
If it's neither collin or gordon, message box "wrong user" and exit sub. If not do nothing.
If it's neither 1234 or 123, message box "wrong password" and exit sub. If not do nothing.


The issue are the following :
Whatever what happen, you are closing userform2 two times.
If we write Gordon and 1234 (not the good combination) we have no error message. Same thing with Collin 123.

I can help you with that, but I have 1 question, what is that userform, is it userform2?
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,685
Members
449,463
Latest member
Jojomen56

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top