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
Mike - 24 Nov 2006 14:48 GMT
Okay, I figured out answer to question #1... I'm an a.s and should drink more
coffee...
Question number 2 stands. lol
Thanks everyone, hope you all got a chuckle!
> 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
[quoted text clipped - 28 lines]
> 1. What am I doing wrong?
> 2. If its an unknown error... how come there's an error number??? LOL
Daniel - 24 Nov 2006 14:55 GMT
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
> 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
[quoted text clipped - 28 lines]
> 1. What am I doing wrong?
> 2. If its an unknown error... how come there's an error number??? LOL
Stefan Hoffmann - 24 Nov 2006 15:14 GMT
hi Mike,
> Function ChkLastRec()
> Dim rs As DAO.Recordset
[quoted text clipped - 12 lines]
> 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 <--
AccessVandal - 27 Nov 2006 03:54 GMT
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
>Mike wrote:
> If rs.BOF Then
[quoted text clipped - 3 lines]
> End If
>End Function