|
-
Sep 14th, 2000, 03:26 PM
#1
Thread Starter
Junior Member
I have a save button on my form and the code behind it is Data1.Updaterecord
The user enters in all there infor to textboxes and clicks this button so the info in stored to the access 97 DB. But most of the time when this is clicked it populates all the textboxes with a previous record....Is there someway to stop this or a better way to save to the database..PLEASE HELP
-
Sep 14th, 2000, 03:48 PM
#2
Monday Morning Lunatic
You can do it by not using the datacontrol. Although this is for DAO, since it is faster for Access:
Code:
Dim db as Database ' Database object
Set db = OpenDatabase("me.mdb") ' Open the Access database
dim rst as recordset ' Recordset, used to retrieve records
set rst = db.TableDefs("MyTable").OpenRecordSet ' Open all records for table "MyTable"
rst.addnew ' Begin adding a new record
rst!FieldA = Text1.Text ' Set text value
rst!OtherField = CInt(Val(Text2.Text)) ' Set integer value
rst.update ' Update record in database
rst.close ' Close recordset
db.close ' Close database
Or something similar.
[Edited by parksie on 09-14-2000 at 05:03 PM]
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 14th, 2000, 03:58 PM
#3
Thread Starter
Junior Member
Do you think you could put some comments in that code..I dont really understand what all of it does exactly..thanks
-
Sep 14th, 2000, 07:35 PM
#4
Thread Starter
Junior Member
How do you know what fields go to which fields?
rst!FieldA = Text1.Text
Like the fieldA.....
IF you have a large table Im not sure how to determine which field corresponds to FieldA
-
Sep 15th, 2000, 02:11 AM
#5
Junior Member
sorry, but even if U have a VERY large table, you have to know names of the fields. Or U should know the order of the information.
If U know names, U use
something like Parksie wrote:
rst!FieldA = Text1.Text
(fieldA is only an example of a name)
If U know the order, U can use
rst.Fields(5) = Text1.Text
but in all cases U have to know what exactly is in the table and which textbox corresponds to which information.
By the way, It's vary useful to name each textbox and each field in a table. Then U can write
rst!EmployeeName = txtEmployeeName.Text
instead of
rst!FieldA = Text1.Text
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|