If - Else Statement Not Working

r-macro

New Member
Joined
Jul 24, 2013
Messages
2
I am not sure why my code is not working. This part of my program is for updating a record. So the user would enter in the license plate number which is the criteria for the record search and then enter in their updates in the remaining text boxes. My problem is that I want my program to send a msgbox if the plate number they entered is not in the database (invalid). with the code I have below it sends a msgbox for a license plate that is not in the database (invalid) but also sends a msgbox for a license plate that is inside the database (valid), which I do not want to occur. How do I fix this?
Thank you in advanced.

Private Sub CommandButton1_Click()

row_number = 0

Do

DoEvents

row_number = row_number + 1

item_in_review = Sheets("Vehicle Records").Range("I" & row_number)

If item_in_review = TextBox1.Text Then

Sheets("Vehicle Records").Range("O" & row_number) = TextBox2.Text
Sheets("Vehicle Records").Range("Q" & row_number) = TextBox3.Text
Sheets("Vehicle Records").Range("R" & row_number) = TextBox4.Text

Else
MsgBox "Plate Number Does Not Exist"
Exit Sub

End If

Loop Until item_in_review = ""

End Sub
 
Last edited:

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
In my experience, what your'e doing is very volatile, because text boxes really suck for vba.

As a result, you probably want to look into error handling, and putting those text box values into actual cells.

Would love to get a real solution that involves your current methodology, but as far as I'm aware, VBA is terrible for this... (Bait, bait bait)
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

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