Total newb question about forms

gustoaf

New Member
Joined
Sep 23, 2008
Messages
4
I have a simple form with a single button on it that will run a query based on user input. Instead of that input returning the spreadsheet-type query results, how can I have the results display in text boxes on the same form?<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
For instance, my form button runs the query:<o:p></o:p>
<o:p> </o:p>
SELECT UNIT_ID.UNIT_ID, UNIT_ID.MNEUMONIC, CORR_CODE.CORR_COND, CORR_CODE.MESSAGE<o:p></o:p>
FROM CORR_CODE INNER JOIN (UNIT_ID INNER JOIN CORR_DATE ON UNIT_ID.UNIT_ID = CORR_DATE.UNIT_ ID) ON CORR_CODE.CORR_COND = CORR_DATE.CORR_COND
WHERE (((UNIT_ID.UNIT_ID)=[Enter Unit ID]));<o:p></o:p>
<o:p> </o:p>
Unit_id.unit_id is a unique key with no duplicates so only one record will return. I would like the 4 ‘select’ fields to populate text boxes at the bottom of the same form that the input button is on. A bonus would be for the text boxes to be hidden until a result is returned.<o:p></o:p>
<o:p> </o:p>
Hope I explained that well enough. <o:p></o:p>
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi,

No need for a command button if you take this approach. Just create a new form by selecting forms and then click Create form by using wizard. Then select your query from the combo box.

Next select the fields that you want on the form and click next. Select the layout, I suggest tabular. Next select the style and then click next and name your form.

Now when you click finish the form will open displaying the fields in textboxes that the wizard has created for you. You can of course change the layout from form design.

Hope that helps.
 
Upvote 0
Sorry just read your post again and I missed that you had a textbox for user input.

Just add a textbox to the form header section of the form created by the wizard. Reference this new textbox in the criteria from your query. Now add this code to the after update event of the new textbox.....
Code:
Option Compare Database
Option Explicit

Private Sub Text14_AfterUpdate()

    Me.Form.Requery    'run the query

End Sub
Now after the user enters criteria, the query will execute and the records will be displayed in the textboxes you created with the wizard.

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,214,645
Messages
6,120,711
Members
448,984
Latest member
foxpro

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