VBA Loop until finding a match from temp data from SQL pull

Morgan_T

New Member
Joined
Aug 9, 2019
Messages
3
So I am currently working a project and I and I need to create verify text given through an input box against an SQL result.

If the number "15" is entered and the sql table contains 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 I need it to save the number variable if a match is found and if not I need it to loop and ask for another number. Seems easy but I'm overthinking it.

number = InputBox("Enter Number")

Set sqlResult = (SQL query for temp information)

Do
If Number = sqlResult.Fields(0) Then
Number = sqlResult.Fields(0)
Else
Number = 0
End If
sqlResult.MoveNext
Loop Until sqlResult.EOF

Help appreciated!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,214,611
Messages
6,120,510
Members
448,967
Latest member
screechyboy79

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