Is this VBA code still vaild?

kyuball

Registered User.
Local time
Today, 08:27
Joined
Jul 6, 2009
Messages
66
I was going through these forums looking for information on making text boxes fill in table fields upon button commands or close of forms, etc. and ran into this post.

You'll could write some code for the form....

Dim db As Database
Dim rs As Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("Orders")

With rs
.AddNew
.Fields("Date") = Me.UnboundTextBoxName.Value
.Update
End With

Place this code on a event, e.g. a click of a button
rs.Close

However, this post was from a while ago (I think the post said 2000) and I was wondering if it would still work on Access 2003?
 
The simple answer is YES. It is not the best written code in the world however. If you describe what you are trying to accomplish maybe someone will have a suggestion you can use.
 
Hey Rural,

Thanks for the quick reply.

As for what I am trying to do, I was trying to get away from bound forms and bound text boxes for future databases so I can stop worrying about how to limit automatic insertion of data into tables. It seemed, after going through a lot of threads here, that standard practice seems to be to use unbound fields and make a button or other command with lines of code that inserts a new record.

As an example, if I were to make a form to fill in fields on a client profile table that has, ummm..., let's say first and last name, date of opening, monthly fee, etc. and wanted to avoid having the .mdb file create a new record automatically without all of the fileds completed because the person entering the data (generally people who are not very meticulous about that) had something else that he or she needed to attend to. I kept asking whether there was a way to stop a form from automatically creating a new record and it occured to me that after reading the threads here that the way to do it is through unbound fields. Generally, as a rule, I try to make forms that fill in one table instead of multiple tables because I gathered that that is the best way to design a database in the first place. I wanted to know if I could make a button with the code above and maybe change up the specific references to fit my database to do something like that.

It seems that what I just described above was such basic knowledge here that it would have been a bother to write up a long winded scenario (like I just did!) just to 1) annoy the generous folks here by asking a "is the sky blue" type of question (you guys are a bit tough on noobs here) and/or 2) be completey ignored. I found the thread with teh above written code after poring through the threads and that's where I find myself.

Would the folks here recommend that I use the above code for future purposes?
 
If you don't use bound forms, you are throwing away most of the power of Access. A simple Me.UnDo in the BeforeUpdate event of a form will throw away any changes made on a bound form. I have only seen one case where using an inbound form was necessary and frankly I can't remember what it was. I believe you would be better served by looking at the easy ways you can stop those unnecessary changes to your tables. Did you look at this particular example yet?
 
Hi

just to add a note that i have made one app with a complete set of unbound forms. The reason for this was it was a requirement to have the complete app in only one form and any other forms be a subform sourceobject change. The main form had 3 subforms one being a contact set.

The issues of not adding new contacts arisen when the mainform was bound to the contact or query. The subform would change to add a contact and then after you filled in the details, you couldn't save the record. This and a few similar issues made me unbind and retest. When it worked, I reconfigured and set up code to manage the data instead.

As a rule, I prefer bound forms but this was a good example of unbound dorms for me...


Nigel
 
Hey Rural,

Thanks for the tip and I went to the link and am attempting to iron out some kinks there as well.

In case there seems to be no way of making the "mouse trap" in that forum work, how would an me.undo work and how can I just plain ole disable the mousewheel and page ups and downs?

BTW, I really appreciate all the help and advice Rural and everyone else posting on this thread....
 
Rural,

You're like a superhero! You come to my aid in this thread AND the other thread...:-)
 

Users who are viewing this thread

Back
Top Bottom