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

UPDATING A RECORD

Status
Not open for further replies.

nwt002

MIS
Jun 16, 2005
58
US
Hello All,

I'm not very experienced in Visual Studio but I did take a course whenever I was in college and I seemed to have forgotten how to do some stuff. I am connecting to an Access 2002 database with the Data control. I have text boxes that are connected to certain fields from my tables and all the connections are working and I can see all my tables and fields in the dropdown boxes in properties. I would like to have a command button that is used to update a record with the information that is entered in the textboxes, but the trouble i'm having is, when I enter stuff in my textboxes, it updates my database without having to click any update button. I can't remember what we did in my class that enabled us to use a button to update records. If anyone can help please let me know. Thanks! Nick
 
that is a normal problem when using BOUND controls.

Search these forums and for BOUND vs UNBOUND controls and you will find plenty of threads regarding this issues.

As for your particular problem I can therefore only sugest that you DO NOT use bound controls and use code to perform the updates WHEN and HOW you wish to do them.

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
If you haven't solved your problem yet you might check the VB online help and look at .editmode. I have used indexed textboxes with bound columns and used locking to prevent input until a button was pushed to unlock when placed in .edit mode then lock again when .update or .cancle update was used. You can hide or show the command buttons based on the mode you are in. I do it with 3 buttons.
 
Keep in mind that Editmode and Edit are not available in ADO, and by extension the ADO Data Control. The creators of ADO didn't see a reason to have an updatable object have an updatable and a non-updatable state, so they scrapped this functionality.
 
There is reference to adEditNone, adEditInProgress, adEditAdd and adEditDelete in the ADO help on MSDN disk 2. That doesn't mean it is avaialble for use with VB6 but as I have used only DAO I can't say for sure.
Sorry if I have mislead anyone. I just looked at the help file
 
Let me correct my last. There IS an EditMode property, there is NOT an Edit method. Sorry to have been careless. (If I knew how to put one of those little red faces, I would put one here!)

It was pretty clear that we were all talking about DAO, billy, but I wanted to spell that out.
 
Hello Bob
Looks good to me. VB6 has a heck of a lot under the hood.
Billyh
 
Thanks Everyone for all your advice. I ended up doing, I guess what you could call a work around, to update my record. I don't know if this would be considered poor programming, but it gets the job done. I went ahead and still used bound text boxes for updating my database. I made the bound textboxes not visible and for each one, I created another textbox that is not bound to anything and put it over the bound textbox on the form. On form_activate I have each unbound textbox = each bound textbox so you can see what info is in the database. Whenever information is entered, it is entered into the unbound textboxes so it does not update the data in the database. I have a cancel button[b/] that just puts theunbound textboxes = the bound textboxes again. If I want to update the information in the database I have an OK button that just makes each bound text box = each unbound textbox, since the bound textboxes update as soon as the information in them changes. Please let me know if you can think of any issues i might run into by doing it this way. Thanks again.
 
the only thing I can say about that is that if you were a programmer working for me you would redo all work as it should have been done in first place.

Very bad.

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Yes, well, hm...Frederico, I'm sure that if he were a programmer working for you you would have given him sufficient management guidance in the first place to prevent him from having to redo all his work, so your point is a bit moot.

nwt002, perhaps I can offer a bit of advice. Most of us don't use data binding in the first place. (Note frederico's first post.) I don't use the data control at all, either, I use ADO (ActiveX Data Objects). Also, I prefer to write a subroutine that "manually" refreshes the text boxes with the current record in the ADO recordset, and call it when I want to. I suspect that most of us prefer to do the same thing.

If you want to learn how to do this, first read up on it and have a go yourself. Then post back with questions as you need to.

HTH

Bob
 
bobrodes,

humm. maybe my post should have been slightly smoother.



but on my OP I did suggest that nwt002 searched for a particular type of issues related to what he was doing, and we did not get any other question related this subject.

One aspect of programming is that if you have questions about something you should ask others, and if given a direction you would at least question it if you don't agree.

It is not visible from the last post that nwt002 did ask such questions, and instead just decided to use a workaround that will not prevent some of the problems with Bound controls anyway. If he/she had come to us asking for more guidance before doing the changes e.g. "I am thinking on doing like this.. is this a good way?" then I am sure that either myself or someone else would have provided more guidance.



mwt002.

Just one possible problem with bound controls. others exist.

situation.
customer maintenance screen.
You have loaded customer information, and are therefore locking the record(s) on the database.
User goes for lunch without canceling/commiting the operation and is out for 2 hours.

During that period those records are locked and no one can use the customer.

How do you get around this issue?

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Yes, he did sort of ignore your advice, didn't he, frederico? I guess I see your point, he could have gone to a little more trouble to follow up on the advice you gave him.

nwt, just for the record, it WAS good advice frederico gave you. Furthermore, it is very true that if you were working for me as a programmer, I would have told you not to use the data control. And, if you had come back with the solution that you showed in your post, I would had you tear it down and do it over again the proper way. On the other hand, you're not working for me, and you'll find out on your own the difficulties in your system in time.

<Please let me know if you can think of any issues i might run into by doing it this way.

Frederico has given you one possible scenario that could cause problems. I suggest that you spend a little time working with data validation and find out some things for yourself. Try, for example, making several of your fields require an entry.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top