Newbie: What am I doing wrong?

M

Mike

I just started playing around with recordsets and trying to move around the
datasheet to perform certain calculations. What I'm first trying to do is
just pull data from a field and enter it into a new field in the record
below, if I can figure out how to do this, I can do my calculations - each
record is an event:
Event1 / DateTime1 / NoCalc
Event2 / DateTime2 / DateTime2-DateTime1

Anyways, my baby step looks like this:
Function ChkLastRec()
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim tblName As String

tblName = "TEST"

Set db = CurrentDb
Set rs = db.OpenRecordset(tblName)

If rs.BOF Then
ChkLastRec = 1
Else
ChkLastRec = 0
End If
End Function

I call this function from a MS Access query, but it gives me unknown error
28 on this line: Set rs = db.OpenRecordset(tblName)

So, I have two questions:
1. What am I doing wrong?
2. If its an unknown error... how come there's an error number??? LOL
 
M

Mike

Okay, I figured out answer to question #1... I'm an ass and should drink more
coffee...

Question number 2 stands. lol

Thanks everyone, hope you all got a chuckle!
 
D

Daniel

Are you sure that your table is named TEST?

Also once you've set your rs variable, you'll need to .moveFirst or Last
depending on the approach being used and add a movement in a loop. Bleow is
an example.

With rs
intRecCount = .RecordCount
If intRecCount <> 0 Then .MoveLast

Do something you want with the recordset

.MovePrevious
.Update
End If
.Close
End With

You can find alot of info on the in the vba help as well as here if you
search by key word.

Hope this helps,

Daniel
 
S

Stefan Hoffmann

hi Mike,
Function ChkLastRec()
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim tblName As String

tblName = "TEST"

Set db = CurrentDb
Set rs = db.OpenRecordset(tblName)

If rs.BOF Then
ChkLastRec = 1
Else
ChkLastRec = 0
End If
End Function
What do you intend to do with that function, cause it is almost useless.
I call this function from a MS Access query, but it gives me unknown error
28 on this line: Set rs = db.OpenRecordset(tblName)
2. If its an unknown error... how come there's an error number??? LOL
Your function works under Acc2003.

Check the references, maybe there are some broken ones (Microsoft DAO).


mfG
--> stefan <--
 
A

AccessVandal via AccessMonster.com

Hi Mike,

Looking at the IF Else and with the ChkLastRec, you want the Function to
return something.
An Integer,Boolean,Variant or String

Try,

Function ChkLastRec() As Integer

as a Integer like True = 1 and False = 0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top