Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating Table Data from an Unbound Form Field

Status
Not open for further replies.

iXPhound

Technical User
Feb 25, 2001
146
0
0
US
Hi Again All:

My question is this (I'm still new and learning with Access):

Say I create a form (frmHyp) with no record source. On this form I have a text box (txtTime) with no control source and a command button (cmdExe). I also have a table (tblHyp) that has one column, Time.

If I run the form and enter "8" into txtTime, what code would I have to put into cmdExe to input that "8" into tblHyp. This maybe a stupid question but I don't want to use tblHyp as the record source for the form.

TIA!!!!!!!
 
Hi,

In cmdExe "Click" event you should try :

dim rs as recordset

set rs = currentdb.openrecordset("SELECT * FROM tblHyp")

rs.addnew
rs("Time").value = me.txtTime
rs.update
rs.close

That should do the trick!
hope it helps. Salvatore Grassagliata
GrassagliataS@hotmail.com
 
One way I have approached this is to create an action query (append query) that picks up the value in the unbound text box and appends it into the table.

In your case the query would be like this:

INSERT INTO tblHyp ( fldTime )
SELECT [Forms]![frmHyp]![txtTime] AS Expr1;

You create this query by:
1. Create New Query. Click Query, Design View... When the window pops up prompting you to select a table/query, DO NOT select a table/query, click Close.
2. Change the query type to an Append Query. Select Query, Append Query, and tblHyp.
3. Select the Field you want to append. In the 'Append to:' row, there's a dropdown, select your field name (fldTime, etc).
4. This is where it gets interesting. You want to enter the fieldname from your form in the 'Field:' row in your query. To do this, place you cursor in the 'Field:' row and select the Wand icon on your toolbar. The Expression Builder window will appear. Expand the +Forms folder, then expand the +All Forms folder and double click on frmHyp. Then double click on the textbox name that you want to append to your table (txtTime) You will see some code appear in the upper window. Click OK. Save the query.
5. Create a button on your form with the wizard. There are several categories you can choose from (Record Navigation, Record Operations, Form Operations, etc). Select the last one - Miscellaneous. And then under 'Actions', select 'Run Query'. Click Next, and Select your append Query name.

I hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top