473,569 Members | 2,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with rs.Update I think?

I'm having some trouble with VB in Access 2000. I have a form that the
user enters in just one number (in this case, it's a base salary) and
then the program is going to do a bunch of math (which is not all
shown) and populate a table with these new, calculated salary values.
I know I shouldn't be storing calculated values in the table, but I
have to have these numbers in there as a lookup too.

Anyway I think I might be getting too complex with this, but any
assistance anyone can give me (or pointers to make it simpler if
possible) would be greatly appreciated.

It errors out at the rs.Update line and I cannot figure out why. The
code is below.

Private Sub Populate_Click( )
' populate the salary schedule columns

Dim rs As ADODB.Recordset
Dim rs2 As ADODB.Recordset
Dim rs3 As ADODB.Recordset
'Dim SQL_query As String
Dim Counter As Integer
Dim BaseSalary As Long
Dim Index As Currency
Dim Salary As Long
'Dim yearsexp As Integer
Dim Updated As Boolean

Set rs = New ADODB.Recordset
Set rs2 = New ADODB.Recordset
Set rs3 = New ADODB.Recordset
Counter = 0
Index = 0

'open the recordset to get all the salary values
rs.Open ("SELECT * FROM salaryschedule" ), CurrentProject. Connection
rs2.Open ("SELECT * FROM contractbase"), CurrentProject. Connection
rs3.Open ("SELECT * FROM indexes"), CurrentProject. Connection

rs.MoveFirst
rs2.MoveFirst
rs3.MoveFirst

'loop with counter based on year of experience and perform
calculations of each salary amount based on year and index pulled from
DB
Do Until Counter = 21
BaseSalary = rs2.Fields("Bas esalary")
Index = rs3.Fields("bac helorsindex")
Salary = (BaseSalary * Index)

'Updated = rs.Update("400" , Salary)
Updated = rs.Update("400" , Salary) 'it errors out here constantly with
"expected function or variable error"
Counter = Counter + 1
rs.MoveNext
rs3.MoveNext
Loop

Am I doing or overlooking something really stupid? Thanks! -Joe
Nov 12 '05 #1
2 3601
DFS

"Joseph Markovich" <jo*@josephmark ovich.com> wrote in message
news:b5******** *************** **@posting.goog le.com...
I'm having some trouble with VB in Access 2000. I have a form that the
user enters in just one number (in this case, it's a base salary) and
then the program is going to do a bunch of math (which is not all
shown) and populate a table with these new, calculated salary values.
I know I shouldn't be storing calculated values in the table, but I
have to have these numbers in there as a lookup too.

Anyway I think I might be getting too complex with this, but any
assistance anyone can give me (or pointers to make it simpler if
possible) would be greatly appreciated.

It errors out at the rs.Update line and I cannot figure out why. The
code is below.

Private Sub Populate_Click( )
' populate the salary schedule columns

Dim rs As ADODB.Recordset
Dim rs2 As ADODB.Recordset
Dim rs3 As ADODB.Recordset
'Dim SQL_query As String
Dim Counter As Integer
Dim BaseSalary As Long
Dim Index As Currency
Dim Salary As Long
'Dim yearsexp As Integer
Dim Updated As Boolean

Set rs = New ADODB.Recordset
Set rs2 = New ADODB.Recordset
Set rs3 = New ADODB.Recordset
Counter = 0
Index = 0

'open the recordset to get all the salary values
rs.Open ("SELECT * FROM salaryschedule" ), CurrentProject. Connection
rs2.Open ("SELECT * FROM contractbase"), CurrentProject. Connection
rs3.Open ("SELECT * FROM indexes"), CurrentProject. Connection

rs.MoveFirst
rs2.MoveFirst
rs3.MoveFirst

'loop with counter based on year of experience and perform
calculations of each salary amount based on year and index pulled from DB Do Until Counter = 21
BaseSalary = rs2.Fields("Bas esalary")
Index = rs3.Fields("bac helorsindex")
Salary = (BaseSalary * Index)

'Updated = rs.Update("400" , Salary)
Updated = rs.Update("400" , Salary) 'it errors out here constantly with
"expected function or variable error"
You're mixing together variable assignments, recordset updates, and what
appears to be a function. Try:
rs.Edit
rs("Salary") = 400
rs.Update

Or is 400 your column name? If so:
rs.Edit
rs("400") = Salary
rs.Update

Counter = Counter + 1
rs.MoveNext
rs3.MoveNext
Loop

Am I doing or overlooking something really stupid? Thanks! -Joe



Nov 12 '05 #2
"Joseph Markovich" <jo*@josephmark ovich.com> wrote in message
news:b5******** *************** **@posting.goog le.com...
I'm having some trouble with VB in Access 2000. I have a form that the
user enters in just one number (in this case, it's a base salary) and
then the program is going to do a bunch of math (which is not all
shown) and populate a table with these new, calculated salary values.
I know I shouldn't be storing calculated values in the table, but I
have to have these numbers in there as a lookup too.

Anyway I think I might be getting too complex with this, but any
assistance anyone can give me (or pointers to make it simpler if
possible) would be greatly appreciated.

It errors out at the rs.Update line and I cannot figure out why. The
code is below.

Private Sub Populate_Click( )
' populate the salary schedule columns

Dim rs As ADODB.Recordset
Dim rs2 As ADODB.Recordset
Dim rs3 As ADODB.Recordset
'Dim SQL_query As String
Dim Counter As Integer
Dim BaseSalary As Long
Dim Index As Currency
Dim Salary As Long
'Dim yearsexp As Integer
Dim Updated As Boolean

Set rs = New ADODB.Recordset
Set rs2 = New ADODB.Recordset
Set rs3 = New ADODB.Recordset
Counter = 0
Index = 0

'open the recordset to get all the salary values
rs.Open ("SELECT * FROM salaryschedule" ), CurrentProject. Connection
rs2.Open ("SELECT * FROM contractbase"), CurrentProject. Connection
rs3.Open ("SELECT * FROM indexes"), CurrentProject. Connection

rs.MoveFirst
rs2.MoveFirst
rs3.MoveFirst

'loop with counter based on year of experience and perform
calculations of each salary amount based on year and index pulled from
DB
Do Until Counter = 21
BaseSalary = rs2.Fields("Bas esalary")
Index = rs3.Fields("bac helorsindex")
Salary = (BaseSalary * Index)

'Updated = rs.Update("400" , Salary)
Updated = rs.Update("400" , Salary) 'it errors out here constantly with
"expected function or variable error"
Counter = Counter + 1
rs.MoveNext
rs3.MoveNext
Loop

Am I doing or overlooking something really stupid? Thanks! -Joe


As far as I can see, you need to return to the basics of opening, updating
and closing one recordset before you open 3. The first and most obvious
thing is this:

Updated = rs.Update("400" , Salary)

Where did this come from? The recordset has a *method* called 'Update' - it
is *not* a function. It looks like you are hoping for it to return a value
of True or False. In fact, you simply write:

rst.Update "MyFieldNam e", 50

To update the field called "MyFieldNam e" with a value of 50. (Do you really
have a field named "400"?)

Even using the update method is slightly unusual and in most of the coding I
see, it is not used at all. In DAO you had to use rst.update but using ADO
you could simply write:

rst("MyFieldNam e") = 50

And in my opinion it is clearer what is going on.
Secondly, and also very importantly is the fact that you have opened a new
recordset without specifying a LockType so you will be left with a default
value of adLockReadOnly. This makes it difficult to update the recordset!
If I had to loop through a recordset, my code might look like this:
Private Sub cmdUpdate_Click ()

On Error GoTo Err_Handler

Dim strSQL As String
Dim cnn As ADODB.Connectio n
Dim rst As ADODB.Recordset
Dim lngCount As Long

strSQL = "SELECT * FROM MyTable"

' Not always the fastest, but anyway:
Set cnn = CurrentProject. Connection

Set rst = New ADODB.Recordset

rst.Open strSQL, cnn, adOpenDynamic, adLockOptimisti c

While Not rst.EOF
lngCount = lngCount + 1
rst("MyField") = lngCount
rst.MoveNext
Wend

Exit_Handler:

On Error Resume Next

If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If

If Not cnn Is Nothing Then
Set cnn = Nothing
End If

Exit Sub

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub

Fletcher
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2611
by: Frnak McKenney | last post by:
I'm using an in-core DataSet as an image of my application's 'database' (a multi-table Access97 mdb file). Updates are made to the DataTables within the DataSet via forms with bound TextBoxes, then written to the database... or at least that's what's supposed to be happening. Unfortunately, I've discovered that while it appears that when...
3
1988
by: Steven Blair | last post by:
Hi, I have a problem understanding the SqlDataAdaptor and the DataSet. I have a dll which has various methods for running stored procedures etc. It also has a method which allows the client to return a DataSet from a table. The client can modify this DataSet and I have wrote a function which will take this DataSet back in and update the...
7
2213
by: Peter D.C. | last post by:
Hi I want to update data hold in several textbox controls on an asp.net form. But it seems like it is the old textbox values that is "re-updates" through a stored procedure who updates a SQL tabel. I know the SP works, because a smalldatetime-field in the database is changed. I've tried to disable viewstate on all textbox controls. Any...
2
4536
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was set to...it is set to false. Can someone show me what I am doing wrong and tell me the correct way? Thank you. In the page load event, I am...
7
3437
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function 'UpdateRegistrant' expects parameter '@EMail', which was not supplied. The field value was null in the database and not changed in the FormView so is...
3
6079
by: Juan Antonio Villa | last post by:
Hello, I'm having a problem replicating a simple database using the binary log replication, here is the problem: When the master sends an update to the slave, an example update reads as follows: UPDATE MainInfo SET dAddress='38 Holland Blvd', dCity='miami', dState='FL', dZip='33000', dCountry='USA', dPhone='999987565',...
6
4941
by: Jeff North | last post by:
I'm using Microsoft SQL Server Management Studio Express 9.00.2047.00 and expriencing problems with setting referential integrity on a link table. The tables' schema is as follows: ------------------------------------------------------------------- CREATE TABLE competencies ( CID bigint identity(1,1) CONSTRAINT pk_CID PRIMARY KEY,...
7
2587
by: Vlado Jasovic | last post by:
Hello, I'm using typed dataset for databinding to windows controls and I'm having some problems. I'm trying to move all business logic to datatable column_changing events and the problem that I'm having is when I change some other column, control value doesn't update immediately until I call endcurrentedit on bindingmanager which doesnt...
11
6052
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know if that's what's causing the behavior or not. It seems like the Update button should at least do something. When the Edit button is clicked, the...
0
7618
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...
0
7926
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. ...
0
8138
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...
0
7983
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...
0
6287
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...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
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...

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.