If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
SQL
Firstly you'd need to create a form then add a command button to it. Then
select the button in form design view and open its properties sheet if its not already open. Then select the On Click event property in the properties sheet. Click on the 'build' button; that's the one on the right with 3 dots. Select 'Code Builder' in the dialogue, and click OK. The VBA window will open at the event procedure with the first and last lines already in place. Enter the lines of code between these two existing lines. The SQL statement is the string assigned to the strSQL variable in the code. In my example its: strSQL = "UPDATE Products " & _ "SET UnitPrice = UnitPrice * 1.1" which increases the price of all products by 10 percent. You'd put your owm SQL in here. Note how the statement is split over two lines for readability in my example by using the _ (underscore) continuation character. Code like this executes an SQL statement to carry out an action which changes the data. I'm assuming this is what you want as you used the word 'execute' in your post. If, however, you are referring not to undertaking an action which changes the data, but retrieving data via a query then the best and simplest way to do that would be to base a form or report on the query and simply open the form or report via a button. The button wizard will set up the code to open a form or report for you. You don't even need to save the query for this; you can simply make the SQL statement the form or report's RecordSource property. Ken Sheridan Stafford, England subs wrote: On Feb 17, 7:09 pm, "KenSheridan via AccessMonster.com" u51882@uwe wrote: One option would be to execute the SQL statement in code, e.g. in a command button's Click event procedu [quoted text clipped - 34 lines] -- Message posted via AccessMonster.comhttp://www.accessmonster.com/Uwe/Forums.aspx/access-queries/201002/1 i am quite new to this- where would i find event procedure--- where would i put my sql statement-- how should i go about doing this in access thanks much -- Message posted via http://www.accessmonster.com |
Thread Tools | |
Display Modes | |
|
|