473,774 Members | 2,191 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating a table from a module - Why won't this work?

153 New Member
Hey guys...the following code doesn't seem to work refering to the line

recSet2.Fields( "DateDifference ") = UntilCompletion
It says the field is not updatable...I'v e never updated a table from a module before so I'm not sure if I am doing this right but the code is pasted below (the variable 'x' has nothing to do with anything as of now, it's something I will need later)(also no need to read the commentary it's more for my own purposes since this is still a learning experience for me):

Public Function DaysToCompletio n() As Long

'Opening tblContracts as recSet1 and recSet2
Dim con1 As ADODB.Connectio n
Dim con2 As ADODB.Connectio n
Dim recSet1 As ADODB.Recordset
Dim recSet2 As ADODB.Recordset
Set con1 = CurrentProject. Connection
Set con2 = CurrentProject. Connection
Set recSet1 = New ADODB.Recordset
Set recSet2 = New ADODB.Recordset
recSet1.Open "tblContrac ts", con1

recSet2.Open "tbldtdiff" , con2
Dim x As Long

'Declaring UntilCompletion as the amount of days until completion
Dim UntilCompletion As Long

'Looping until EOF (until the last record for EndDate in tblContracts... so
'someone else would have declared recSet1.Open
'"tblWhateverYo urTableNameIs", con1 which means
'connection1 and then to open a field in that recordset you type
'recSet1.Fields ("fieldname" ))
x = 0

recSet1.MoveFir st
Do Until recSet1.EOF
' End Date must be in quotes or will not work
UntilCompletion = DateDiff("d", Date, recSet1.Fields( "EndDate"))
Debug.Print UntilCompletion
recSet2.Fields( "DateDifference ") = UntilCompletion
recSet1.MoveNex t
x = (x + 1)
Loop

'Clearing recSet1 and Con1 (Connection1)
recSet1.Close
recSet2.Close
con1.Close
con2.Close
Set con1 = Nothing
Set con2 = Nothing
Set recSet1 = Nothing
Set recSet2 = Nothing

End Function
Dec 18 '06 #1
9 1879
MMcCarthy
14,534 Recognized Expert Moderator MVP
Try this ...

Expand|Select|Wrap|Line Numbers
  1.       recSet2.Edit
  2.       recSet2.Fields("DateDifference") = UntilCompletion
  3.       recSet2.Update
  4.  
Mary
Dec 19 '06 #2
Kosmos
153 New Member
Thanks...I have tried this but it has not worked for me...do I need a special library to run this code? It says it's out of range of, at least, my declared public variable?

Well actually this is the exact error message:
Method or data member not found (Error 461)
but it refers to that first line of code that declares the public variable...this is something that only happens once I enter this code
Dec 19 '06 #3
Kosmos
153 New Member
this has been my solution so far

Do While FigureOut=False
SlamHeadOnDesk
Loop
Dec 19 '06 #4
Kosmos
153 New Member
Furthermore I guess I don't have the option of .edit but rather .editmode and when I try that I get the error "Invalid Use of Property"
Dec 19 '06 #5
Kosmos
153 New Member
Ahh finally I figured it out
Here is the code...I figure it may be useful in some way or another...espec ially considering this line "recSet2.Op en "tbldtdiff" , con2, adOpenKeyset, adLockOptimisti c" is very confusing...the re aren't enough places that explain these options when opening a recordset...I just went through all the options and it worked finally....what the heck does lock optimistic mean? lol

Option Compare Database

Public Function DaysToCompletio n() As Long

'Opening tblContracts as recSet1
Dim con1 As ADODB.Connectio n
Dim con2 As ADODB.Connectio n
Dim recSet1 As ADODB.Recordset
Dim recSet2 As ADODB.Recordset
Set con1 = CurrentProject. Connection
Set con2 = CurrentProject. Connection
Set recSet1 = New ADODB.Recordset
Set recSet2 = New ADODB.Recordset
recSet1.Open "tblContrac ts", con1
recSet2.Open "tbldtdiff" , con2, adOpenKeyset, adLockOptimisti c

Dim x As Long

'Declaring UntilCompletion as the amount of days until completion
Dim UntilCompletion As Long

'Looping until EOF (until the last record for EndDate in tblContracts... so
'someone else would have declared recSet1.Open
'"tblWhateverYo urTableNameIs", con1 which means
'connection1 and then to open a field in that recordset you type
'recSet1.Fields ("fieldname" ))
x = 0

recSet1.MoveFir st
Do Until recSet1.EOF
' End Date must be in quotes or will not work
UntilCompletion = DateDiff("d", Date, recSet1.Fields( "EndDate"))
Debug.Print UntilCompletion
recSet2.AddNew
recSet2.Fields( "DateDifference ") = UntilCompletion
recSet2.Update
recSet1.MoveNex t
x = (x + 1)
Loop

'Clearing recSet1 and Con1 (Connection1) and recSet 2 and Con1
recSet1.Close
recSet2.Close
con1.Close
con2.Close
Set con1 = Nothing
Set con2 = Nothing
Set recSet1 = Nothing
Set recSet2 = Nothing

End Function
Dec 19 '06 #6
NeoPa
32,573 Recognized Expert Moderator MVP
Thanks...I have tried this but it has not worked for me...do I need a special library to run this code? It says it's out of range of, at least, my declared public variable?

Well actually this is the exact error message:


but it refers to that first line of code that declares the public variable...this is something that only happens once I enter this code
Where is DaysToCompletio n() defined?
You declare a reference to it but it doesn't seem to be defined anywhere.
Dec 20 '06 #7
NeoPa
32,573 Recognized Expert Moderator MVP
what the heck does lock optimistic mean? lol
LockTypeEnum
Specifies the type of lock placed on records during editing.

Constant Value Description
adLockBatchOpti mistic 4 Indicates optimistic batch updates. Required for batch update mode.

adLockOptimisti c 3 Indicates optimistic locking, record by record. The provider uses optimistic locking, locking records only when you call the Update method.
adLockPessimist ic 2 Indicates pessimistic locking, record by record. The provider does what is necessary to ensure successful editing of the records, usually by locking records at the data source immediately after editing.
adLockReadOnly 1 Indicates read-only records. You cannot alter the data.
adLockUnspecifi ed -1 Does not specify a type of lock. For clones, the clone is created with the same lock type as the original.


This should help explain that.
Dec 20 '06 #8
Kosmos
153 New Member
Yep, thanks...I posted the entire module here: http://www.thescripts.com/forum/thread579007.html

thought someone could use it in the future

once I figured that lock stuff out I just had one of those moments when everything came together and code started spewing out of my fingers and sweat glands....heck I even peed the longest do while loop ever ....I feel empowered!!!!
Dec 20 '06 #9
NeoPa
32,573 Recognized Expert Moderator MVP
Yep, thanks...I posted the entire module here: http://www.thescripts.com/forum/thread579007.html

thought someone could use it in the future

once I figured that lock stuff out I just had one of those moments when everything came together and code started spewing out of my fingers and sweat glands....heck I even peed the longest do while loop ever ....I feel empowered!!!!
lol

Good for you Kosmos.
Dec 27 '06 #10

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

Similar topics

11
16226
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? 1) simply UPDATING the values for all fields in the table, whether or not any particular field has actually changed 2) running a second SELECT statement and comparing the $_POST vars to the returned values, and only UPDATING those that have...
2
2929
by: Jaime Wyant | last post by:
*long post alert!* Can anyone give me some pointers on writing "self-updating" python programs? I have an application that is almost ready for beta testing. I want to be able to fix any bugs and push the updates out. I have a *very vague* idea of how to attack this. The client will have an auto-update feature that will hit the webserver via xml-rpc, asking for updates. The server responds, sending back any updated modules.
2
2014
by: George | last post by:
The flow of my app is as follows 1) Pull up an order and change the quantity of a textbox item. (Ex: change the quantity from 1 to 2 2) Click on the Update button 3) When the page posts back you should see the updated quantity of the item. (by the way, in some cases there will be multiple lines for an order...this is where the problem comes in. What happens is that the process works...for the first row of data only. I need the app to...
2
974
by: amber | last post by:
Hello I can't get my update command to work.. I've used the sqlDataAdapter wizard to create a dataAdapter sqlDA_CB_LP, and it created the 'UPDATE' code as follows Me.sqlDA_CB_LP.UpdateCommand = Me.SqlUpdateCommand Me.SqlUpdateCommand4.Connection = Me.SqlConnection Me.SqlUpdateCommand4.Parameters.Add(New System.Data.SqlClient.SqlParameter("@STR_COMMENT", System.Data.SqlDbType.NVarChar, 1073741823, "STR_COMMENT")
8
4615
by: Chris A via AccessMonster.com | last post by:
I have an interesting problem that I have yet to come accross that I can't change data structure on because it is an export from filemaker I am reformatting for another dept. anyway. I have a table like so... Table 1 Field1 Field2 Field3 E1 April 2006 AA, BB, CC E2 April 2006 AA, BB, CC,DD, EE E3 April 2006 AA, BB
18
3801
by: TORQUE | last post by:
Hi, Im wondering if anyone can help me with a problem. I have a form with more than 50 unbound fields. Some of the fields will be blank from time to time. This seems to be where im having trouble. I have tried keeping some of the fields bound and when I use the save button it has been saving as 2 different records. This is unacceptable. This is what I have, can anyone help me out with this?
33
3353
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range of 20 steps) On the admin page the steps are listed, in "order" order and the user can create new steps and assign an order and all is well. The problem may come in using a renumber function which should take the steps in their current order...
2
3321
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi All! I am with a situation where I am not getting the right updating to the form's fields. The situation is the following one: I have one combobox and one textbox. I am using the CurrentChanged event of the BindingSource of the combobox to update the textbox. When selecting an item in the combobox or when selecting a row in the grid, it is updating the textbox correctly. The problem is when I apply a filter in the grid, and then...
6
7785
by: MLH | last post by:
Utilities to recover tbl removed from TABLE tab of database window with the DELETE key?
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9915
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4014
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.