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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Entering Data into Table from Form

Status
Not open for further replies.

snypa

Technical User
Nov 30, 2000
3
US
Hello everyone,

I am a new user and have been banging my head trying to figure out how to do this simple little thing!!

I have a field on my form that is derived from another field on that form. I want to place this derived data into a corresponding field in the underlying table. This is the code I am trying to do this with:

Private Sub Rank_AfterUpdate()
Dim dbs As Database
Dim rst As Recordset

Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("TblStudents")

rst.Edit
rst!Rank = Me!Rank
rst.Update

rst.Close
dbs.Close
End Sub

I don't get any errors or messages, but it also doesn't fill the information into the table - although it shows up on the form.

Any help is greatly appreciated!!

Thanks,

Bob
 
try this
Click on the "Tables TAB"
Single click on your table
click the "Insert" menu then "AutoForm"

It may take a few seconds to make a form.
Now at the bottom of the form are the navigation buttons
|<< < > >>| >*

click on the far right one to make a new record.

OK

DougP, MCP
dposton@universal1.com

Ask me how Bar-codes can help you be more productive.
 
Hi Doug,

Thanks for the reply, but... that's not what I am looking to do.

I have the form set up, and it will fill in all of the fields that have the &quot;Control Source&quot; relating to a field in the table. The field that I want to have entered has as its &quot;Control Source&quot; some code that derives its value from another field on the form. This derived value is the value that I cannot get to enter into the table.

Any other hints?

Thanks again,

Bob
 
Here is some stuff I copied from somewhere???
Example shows how to add data to 3 tables at the same time using VBA code.
--------------------------
Dim db As Database
Dim rst1 As Recordset
Dim rst2 As Recordset
Dim rst3 As Recordset

Set db = CurrentDb
Set rst1 = db.OpenRecordset(&quot;Table1&quot;)
Set rst2 = db.OpenRecordset(&quot;Table2&quot;)
Set rst3 = db.OpenRecordset(&quot;Table3&quot;)

rst1.AddNew
rst1!Yourfield = Somedata '<<<<<<< put data into table1
rst1!Yourfield2 = Somedata2
rst1.Update

rst2.AddNew
rst2!Yourfield = Somedata '<<<<<<< put data into table2
rst2!Yourfield2 = Somedata2
rst2.Update

rst3.AddNew
rst3!Yourfield = Somedata '<<<<<<< put data into table3
rst3!Yourfield2 = Somedata2
rst3.Update

rst1.Close
rst2.Close
rst3.Close
db.Close

This may help with use of the &quot;AddNew&quot; command...good luck.
 
To JfHewitt,

Thanks for the reply. That is basically what I have.

I tried changing the .edit to .addnew but it didn't make any difference.
The data from that one field is not being put into the table (Everything else shows up in the table).

Any ideas?
 
Just as a thought, could you trick it into thinking you manually entered it?

I was thinking that once you finish entering your data and the derived value is placed into the other field, why don't you use the AfterUpdate to change the focus to the derived field: DerivedField.SetFocus and then immediately have it go to the next field you would normally go to: NextField.SetFocus.

This might trick it into thinking you actually manually entered it. I am not sure if this will work but it was just a thought.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top