Userform - Passing input from TextBox into a SQL query - different tabs output to diff sheets?

Smeghead

New Member
Joined
Mar 12, 2013
Messages
35
Hi all,

at the moment, I have quite a few separate files which are used to bring back roughly the same data from a SQL database, but the SQL is slightly different on each file (basically different query parameter(s) on each file).

I'd like to consolidate these and create a userform to streamline this. I've created a rough design here: http://i.imgur.com/OAiCoLD.jpg

Not having extensive experience with userforms before, I have a few questions:

1. I'd like each tab to run a different SQL query, passing anything in the TextBox as parameters, then output to a specific sheet. Is this possible?

2. With my current files which just use the Excel parameters when refreshing, I use BETWEEN in the SQL (i.e. where WaveNum BETWEEN ? AND ?). If I just had one WaveNumber data to print off, I would enter in the same number for both parameters. Would it be easier to basically have each tab just use a single SQL statement (i.e. BETWEEN ? AND ?), and if a number is entered into the "single" box, it uses that for both BETWEEN parameters, and if numbers are entered in both the between TextBoxes, use that for parameter1 and 2? Or could/should I use a separate SQL statement (i.e. WaveNum = ? + WaveNum BETWEEN ? AND ?) for each box? Not sure which would be easier.

Finally, of course I'm going to try and look into this myself, but if anyone has any suggested reading material on hand to get the passing of the TextBox into the SQL code, that would be much appreciated.

Thanks.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,143,637
Messages
5,719,962
Members
422,251
Latest member
bonebreaker100

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
Top