473,382 Members | 1,809 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,382 software developers and data experts.

Defining and Navigating recordsets in VBA

I'm using Access2000. I have one table with employee salary
information. I need to calculate the bi-weekly gross pay (BWG) for
each employee. The BWG is slightly different for leap years. I want
to be able to update all employees' BWG with one mouse click. I've
written a function in a module to do this, but I'm getting an error
"type mismatch" and the line
Set rs = db.OpenRecordset("tblEmployees")
is highlighted.

Below is my entire code. I'm trying to follow instructions from a
book, and I don't know why this isn't working correctly.

Any help (or suggestions of a better way to do this) is appreciated.

Public Function BWGUpdate()
' calcualte and display bi-weekly gross

Dim intYear As Integer ' current year
Dim db As Database
Dim rs As Recordset
Dim fldSal As Field ' salary
Dim fldBWG As Field ' bi-weekly gross

Set db = CurrentDb()
Set rs = db.OpenRecordset("tblEmployees")

' get current year
intYear = Val(Right(Date, 4))

rs.MoveFirst
Do While Not rs.EOF
'check for leap year
If blnLeapYear(intYear) Then
rs(fldBWG) = rs(fldSal) * 0.038251
Else
rs(fldBWG) = rs(fldSal) * 0.038356
End If

rs.Update
rs.MoveNext
Loop

rs.Close

End Function

Public Function blnLeapYear(intYear As Integer) As Boolean
' check if current year is a leap year
' if 2/29/intYear is a valid date, we are in a leap year
blnLeapYear = IsDate("2/29/" & intYear)
End Function
Nov 13 '05 #1
2 3564
Access 2000 and newer uses ADO by default instead of DAO. Some of the
component names, such as Recordset, are the same. The best way to handle
this problem is to explicitly specify which you want to use.

Dim db As DAO.Database
Dim rs As DAO.Recordset

If this causes a compile error, in the code window go to Tools|References
and make sure there is a check next to Microsoft DAO 3.6 Object Library.
--
Wayne Morgan
MS Access MVP
"RBohannon" <ra*****@hotmail.com> wrote in message
news:ad*************************@posting.google.co m...
I'm using Access2000. I have one table with employee salary
information. I need to calculate the bi-weekly gross pay (BWG) for
each employee. The BWG is slightly different for leap years. I want
to be able to update all employees' BWG with one mouse click. I've
written a function in a module to do this, but I'm getting an error
"type mismatch" and the line
Set rs = db.OpenRecordset("tblEmployees")
is highlighted.

Below is my entire code. I'm trying to follow instructions from a
book, and I don't know why this isn't working correctly.

Any help (or suggestions of a better way to do this) is appreciated.

Public Function BWGUpdate()
' calcualte and display bi-weekly gross

Dim intYear As Integer ' current year
Dim db As Database
Dim rs As Recordset
Dim fldSal As Field ' salary
Dim fldBWG As Field ' bi-weekly gross

Set db = CurrentDb()
Set rs = db.OpenRecordset("tblEmployees")

' get current year
intYear = Val(Right(Date, 4))

rs.MoveFirst
Do While Not rs.EOF
'check for leap year
If blnLeapYear(intYear) Then
rs(fldBWG) = rs(fldSal) * 0.038251
Else
rs(fldBWG) = rs(fldSal) * 0.038356
End If

rs.Update
rs.MoveNext
Loop

rs.Close

End Function

Public Function blnLeapYear(intYear As Integer) As Boolean
' check if current year is a leap year
' if 2/29/intYear is a valid date, we are in a leap year
blnLeapYear = IsDate("2/29/" & intYear)
End Function

Nov 13 '05 #2
Thanks for the help.

Randy
Nov 13 '05 #3

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

Similar topics

17
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset...
6
by: Steve Jorgensen | last post by:
I keep having problems in which ADO disconnected recordset work under some circumstances, but lose all their data at other times, having no rows or fields, though the recordset object still exists....
2
by: Pieter Linden | last post by:
The answer to this one is probably "test it yourself and find out!", but I'll ask anyway. Pursuant to my previous question - sending separate recordsets to Word using the CreateTableFromRecordset...
1
by: lakshmi | last post by:
Hi all, I recently rewrote a data intensive C++ program in C#. The C++ program was traversing 3 recordsets that were all open at the same time. I replaced those 3 recordsets with 3 .NET data...
16
by: Randy Harris | last post by:
I was inspired by the recent discussion of returning multiple recordsets to ADO from a stored procedure. (Amazed is probably more accurate). I asked about how to accomplish same with Oracle and...
24
by: Donald Grove | last post by:
I want to populate an array with values from an ado recordset (multiple rows) I use the absolute position of the cursor in the recordset to define the row of my array to be populated. I have a...
4
by: mrmagoo | last post by:
I'm building a vb.net Forms project that is getting data from a SQL Server database. One of the main goals of the project is to be really responsive to events, such as textbox change events. I...
1
by: JohnMOsborn | last post by:
I am designing an Access database that will use tab controls. Normally, you place different sets of fields on each page of the tab control – like Fields1-3 on Page 1, Fields 4-6 on Page 2, etc. In...
4
by: rdemyan via AccessMonster.com | last post by:
Can someone help me with creating code that will look for DAO recordsets in modules and then check to see if the recordset is also closed in the module. All of my recordsets are of the form rs*...
0
by: in10se | last post by:
I have a .NET 2.0 application that uses the WebBrowser control. Because all of my pages are generated dynamically, I am catching the Navigating event, cancelling it, and performing my own operations...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.