473,385 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Using variable I/O in same Sub Procedure - rs.update

28
Good Evening, "Long time listener, first time caller."

MS Access 2007 - VBA - DAO

I have a procedure that updates values from textboxes on a form to a table with a rs object update method. Within that same procedure I am looking to pass the values back out to the same form with a different recordset. Is there a danger or reason for concern given the rs.update happens within the same sub I'm pulling the table values from? Or is there a "reasonable" time-frame I should give the write event to the table?

Thanks,
P

Example:

Expand|Select|Wrap|Line Numbers
  1. button_click()
  2. rs.AddNew
  3. rs!myvalue = text1
  4. rs.update
  5.  
  6. .....more code......
  7.  
  8. db.openrecordset
  9. rs.fields("myvalue") = text1
  10.  
  11. End Sub
  12.  
Feb 14 '14 #1

✓ answered by jimatqsi

Once you do the rs.update you're good to go, there's no delay to worry about. However, if you're writing new records you should follow the rs.update with
Expand|Select|Wrap|Line Numbers
  1. rs.bookmark=rs.lastmodified
Jim

7 1111
jimatqsi
1,271 Expert 1GB
No problem, but I'm not at all sure about the code you posted.

First, be sure to add
Expand|Select|Wrap|Line Numbers
  1. if me.dirty then me.dirty=false
before executing the code behind the form (between lines 1 and 2 above). That writes any changes on the screen to the recordset.

You haven't shown enough code for us to know for sure what is going on. Presumably rs and db have been defined and set elsewhere. But if the field is already on the screen it's not clear why you would need to pass the value back to the screen. That's where you got it to begin with.

Forget screens and recordsets for moment. Tell me if the piece of data that is being updated is in two different tables or not. If two different tables are needing to be udpated, the form on the screen can do one and your vba code can reach out to the other table and do that one. But if you're just trying to refresh the screen to get the data you just added to some table, and the form itself can not do that update, then you need only do a
Expand|Select|Wrap|Line Numbers
  1. me.requery
to pull a new copy of the recordset onto the form.

Jim
Feb 15 '14 #2
pwag
28
Hi Jim,

Thanks for taking the time to help. I appreciate your time.

Let me preface with stating all of my objects are unbound. I wasn't completely clear with my explanation. My code is working fine so it's more of a question about the "predictability" of Access or Ace when and how it's writing to a table. Basically, can I pull out a value from the table I just wrote to in the same sub procedure?

1. Button Click

2. Use record-set behind an unbound button to save a "New" record to a table.

3. I then pull out the primary key value (which is autonumber), back to the form front end to a text box. (My conern is here. Will the autonumber have enough time to generate from step 2 before the code moves to this 3rd step?)

4. End Sub


I'm pulling out the primary key immediately to my form so I can then pass it to another form. Hope this makes sense.

Thanks again!
Paul
Feb 16 '14 #3
jimatqsi
1,271 Expert 1GB
Once you do the rs.update you're good to go, there's no delay to worry about. However, if you're writing new records you should follow the rs.update with
Expand|Select|Wrap|Line Numbers
  1. rs.bookmark=rs.lastmodified
Jim
Feb 16 '14 #4
NeoPa
32,556 Expert Mod 16PB
pwag
"Basically, can I pull out a value from the table I just wrote to in the same sub procedure?"
Simply put - Yes. As Jim says, once the .Update() has been executed the table contains the data.

There is a caveat to that, which is that this behaviour would be modified if you were using transactions in your code. In this latter case the data would be ready to access only when the transaction is completed. I suspect that isn't an issue for you though.
Feb 16 '14 #5
pwag
28
Thanks Jim and NeoPa,

NeoPa,

Could you briefly explain what you mean by "transactions?" You're correct, it probably doesn't apply here though.

Paul
Feb 16 '14 #6
jimatqsi
1,271 Expert 1GB
Paul, transaction processing is a way to start a posting process, for example, and un-do whatever is done if the process does not finish completely without error. You do it all or you do nothing.

Here is a good MS article on the topic.
http://msdn.microsoft.com/en-us/libr...ffice.12).aspx

Jim
Feb 16 '14 #7
NeoPa
32,556 Expert Mod 16PB
That about says it Paul. Not much I can add to that.
Feb 17 '14 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: aish | last post by:
I want to send email using sql stored procedure.my code is work fine in my local sqlserver account. when I use my online sql server it display this error. EXECUTE permission denied on object...
2
by: Rami | last post by:
Dear all, i would like to ask if it possible to fill a dataset using one stored procedure, for example: we have two tables ( emp ) and ( Dept ) can i use the following stored procedure...
3
by: Justin | last post by:
I am trying to do a simple update of a database using a stored procedure. I have get the following error when executing the code: "Procedure or function UpdateDetails has too many arguments...
1
by: Matthew Curiale | last post by:
I am trying to create a search page for a database that will display in a repeater, using a stored procedure. The page_load is fine, and calls/displays all rows from the db just fine. When I input...
0
by: george | last post by:
Hi world! Anyone experienced building gridview in Oracle environment using stored procedures, please help! Right now, I have issues using Oracle SP, I spent a whole day on this and still...
1
by: rsdev | last post by:
Hi, I'm trying to find a way to create an XML file from an SQL table row using a stored procedure. This is what I have so far, but it is incomplete; CREATE PROCEDURE dbo.xml_header...
0
by: svgeorge | last post by:
I want to update several tables using one stored procedure. How can i do this I mean the syntax.etc. declaration etc. I know the basic syntax as below CREATE PROCEDURE <Procedure_Name, sysname,...
7
by: bprocopio | last post by:
Please help. I'm stumped. I need to create a dynamic variable in a procedure that will be used to update a variable of the same name in a table. i.e. the name in tblAnalysisScores are...
1
by: santhanalakshmi | last post by:
Hi, Any one, please give me a clear description of the Stored Procedure.What is the main benefits of using a Stored Procedure in SQL ? Thanks in advance
1
by: dosa | last post by:
hello can i ask how can i put a variable copy in update query if i write this give me a wrong: sql="UPDATE book_info SET num_copies="copy" "+ " where num="+Request.form("No_book");...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.