Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 16th, 2007, 11:04 AM
Authorized User
 
Join Date: Jul 2006
Location: dera ismail khan, nwfp, Pakistan.
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to naveed77 Send a message via Yahoo to naveed77
Default problem in updating records

dear reader,

i m new to vb6 and access database, i m working on a project, well i want to update a record then it updates but in database it overwrites on first record not its original location.

here is the code that i use,

private sub cmdupdate()

dim tb as new adodb.recordset

tb!letter=txtletter.text
tb!date=date.value
tb!subject=txtsubject.text

tb.update
clearfields

end sub

where is the problem or please tell me the right code so that record must be updated on its original location in database.

thnq in advance.
Reply With Quote
  #2 (permalink)  
Old January 16th, 2007, 12:13 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

please don't cross post....

http://p2p.wrox.com/topic.asp?TOPIC_ID=54910

HTH

Gonzalo
Reply With Quote
  #3 (permalink)  
Old January 16th, 2007, 12:18 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What do you mean by "original location"?

I assume there is more code than you posted, since the code sample you provide will not work, since there is no connection, and no record or records have been retrieved for you to operate on.

In other words, the code you posted will raise an error, so how are you getting it to overwrite on "first record", or do anything at all, for that matter?

Woody Z
http://www.learntoprogramnow.com
Reply With Quote
  #4 (permalink)  
Old January 18th, 2007, 11:45 AM
Authorized User
 
Join Date: Jul 2006
Location: dera ismail khan, nwfp, Pakistan.
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to naveed77 Send a message via Yahoo to naveed77
Default



private sub cmdupdate()
dim db as new adodb.connection
dim tb as new adodb.recordset

tb.open ("Select letter, subject, date from record "), db, adopenkeyst, adlockoptimistic


if not(tb.bof and tb.eof) then

tb!letter=txtletter.text
tb!date=date.value
tb!subject=txtsubject.text

tb.update
end if

clearfields

end sub

on running program, i face an error that is

" cannot perform operation when the object is open"

while sometimes i also get an error that is

"cannot perform operation when the object is closed"

i want to update the record on its right position in the database. coz it overwrites on very first record in the table. so please solve it as u soon as possible

thnq.v much
Reply With Quote
  #5 (permalink)  
Old January 18th, 2007, 12:06 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

you are still not connecting the recordset to a database!!!

you dimmed a db object but never open it not given it a connection string...

also with that select it will always update the first record of the table, you are not looking for the specific record that you want to update...



HTH

Gonzalo
Reply With Quote
  #6 (permalink)  
Old January 18th, 2007, 06:00 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay - your two errors might seem contradictory, but they are in regards to two different things you are doing.
Your " cannot perform operation when the object is open" probably has to do with you trying to set some property on the recordset after the recordset is open. Of course, as Gonzalo states, you are never opening any recordset in the code you are showing.
Your second error "cannot perform operation when the object is closed" probably has to do with you attempting to use your recordset without it being opened.

So... here is the problems with trying to help you: Your code as shown cannot possibly work, and you state that sometimes you get one error, sometimes the other - which, from the snippet you show is impossible as well. You would ALWAYS get one or the other error, but not sometimes one, and sometimes the other. This tells me that you are running your code and getting the one, and then changing your code and getting the other. If you want someone here to help it would be a good idea for you to do a better idea of isolating your problems.

In other words:
1 - Set up a test that gets one of those errors and consistently gets that one error
2 - Show us that exact code. That is COMPLETE code. For example, you have a call to a clearfields method that is not shown. I would suggest you remove that call until you have your other problems isolated, identified, and fixed.
3 - Show us the COMPLETE error message, with the error numbers and everything.

Gonzalo is also correct about your code not specifying the record you want to update. You need a select statement that returns only the record you wish to work with.


Woody Z
http://www.learntoprogramnow.com
Reply With Quote
  #7 (permalink)  
Old January 19th, 2007, 11:50 AM
Authorized User
 
Join Date: Jul 2006
Location: dera ismail khan, nwfp, Pakistan.
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to naveed77 Send a message via Yahoo to naveed77
Default

ok thnq for nice suggestions but my dear friends, would u both tell me how can i connect db here in this code and also how can i use select statment tell me by using code plz coz this is the problem that i m facing, so tell me if u face the same problem wat will u do (keep in mind i m new to vb:))
 i would b grateful.
Reply With Quote
  #8 (permalink)  
Old January 19th, 2007, 12:21 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There are several ways to do this.

But first let me mention that you need to learn how to do google searches for information - there are hundreds of examples of this on the internet - you could have had your code working right away if you would just search for a tutorial on how to do this.

Secondly, I am sure many here would be happy to give you this sort of information if you had asked for it. What you imply in your first post is that you already are opening the connection and using it, otherwise you wouldn't have been able to even change the wrong records. So, please learn to ask your questions correctly, and not give false information that is misleading. You'll get your help much quicker that way, and not make everyone feel like they are wasting their time with you.

You have declared your connection object that you call db
After declaring it, you need to instantiate it, and open it:

Code:
    Set db = New ADODB.Connection
    db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=password;Data Source=" & App.Path & "\YourDatabase.mdb;"
    cn.Open


Of course, you will have to use the actual path to your database if it is not in the app path.

As far as the select statement goes, your select statement needs to be able to return the record you want to work with. I have no way of knowing from your posts how your table is designed, but I will assume there is an id column that is the primary key. You would use something like this in that case:

Code:
tb.open ("Select letter, subject, date from record where id = " & lngId), db, adopenkeyst, adlockoptimistic
Of course, you will need a value in lngId that contains the id number of the record you wish to retrieve and edit.

Make sense?




Woody Z
http://www.learntoprogramnow.com
Reply With Quote
  #9 (permalink)  
Old January 22nd, 2007, 10:22 AM
Authorized User
 
Join Date: Jul 2006
Location: dera ismail khan, nwfp, Pakistan.
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to naveed77 Send a message via Yahoo to naveed77
Default

thnq mr. woodyz, well, if u didnt want to tell i didnt asked specially from u
but it seems that ur behaviour towards new comers are disappointed coz ur
wordings like make sense, learn to ask etc are much more disappointing,
always adopt polite way so that new one can ask with courage not with fear.
so plz dont mind and make proper way while briefing or helping someone else
ur well wisher.
Reply With Quote
  #10 (permalink)  
Old January 22nd, 2007, 11:20 AM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

"Make Sense?" is merely a question which is asking if you can make sense of the explaination provided. If it does "Make Sense" then you have your solution, but if it doesn't, then all you have to do is provide some information about what you didn't understand so it can be explained in a way that does "Make Sense" to you. I mean no disrespect, I am just asking - did the information "Make Sense" to you? You are the one looking for help - and I am spending my time analyzing your problem - and if I can't "Make Sense" of your question then I ask questions back to clarify.

If it is your intention to only accept help from people who follow your hidden rules for politeness you will probably end up allienating those most capable of helping.

Sorry you are disappointed. Regardless, you will find that forums will give you much more value if you learn to properly define your problem so that it is as easy to understand as possible. Remember - the people supplying answers here are just trying to help - it is in your best interest to make it as easy as possible for them to understand your problem. If you don't want that help, it is up to you.

Woody Z
http://www.learntoprogramnow.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in updating records & finding records naveed77 VB Databases Basics 1 January 16th, 2007 12:12 PM
problem in updating records & finding records naveed77 VB How-To 1 January 16th, 2007 12:10 PM
Updating records help bspradeep Classic ASP Databases 29 September 9th, 2003 07:00 AM
Updating Records marmer Classic ASP Databases 1 August 23rd, 2003 11:12 AM
Updating records help bspradeep Classic ASP Databases 0 July 7th, 2003 10:51 PM



All times are GMT -4. The time now is 12:10 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.