X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Function Get Previousvalue Of Record Not Working, Access 2016    
post Mar 3 2018, 04:20 AM

Posts: 21
Joined: 2-December 17

So I have this function in a standard module
Public Function GetPreviousValue(frm As Form, strField As String) As Variant
On Error GoTo Err_Handler
'Purpose: Return the value from the previous row of the form.
Dim rs As DAO.Recordset

Set rs = frm.RecordsetClone
rs.Bookmark = frm.Bookmark
GetPreviousValue = rs(strField)

Set rs = Nothing

Exit Function

If Err.Number <> 3021& Then 'No current record
Debug.Print Err.Number, Err.Description
End If
GetPreviousValue = Null
Resume Exit_Handler
End Function

When I put this: =GetPreviousValue([Forms]![frmweeklyappointments]![saturdaysubform].[Form], "patientname")
as a data source for a textbox in my subform, it works fine, but when I call the same function in the Current Event of my subform, it returns null value! why is this?? Thank you.
Go to the top of the page
post Mar 3 2018, 05:59 AM

Posts: 1,184
Joined: 26-January 06
From: .....the wiregrass (either you know or you don't)

I have this same type of problem a lot. I think it involves referencing and scope. When you call from one main form....the textbox may be referenced differently than it is from another form (like subform). I sometimes have to toy with the reference for hours before i get it right. But you are using a Global function called from.....oh a subform.


looks like you are referencing a textbox called patientname that is located on subform saturdaysubform that is located on form frmweeklyappointments

I find that the brackets are generally not needed unless the name has spaces or special characters (which should be avoided in names since that practice can create many wild goose chases).

The bang (!) versus the dot(.) dilemma. Honestly, I find no hard and fast rule about these...sometimes they seem interchangeable and sometimes not. So, I'm no help there (I don't think anybody knows that answer).

One tool that is use is a break in the function and then I addwatch to the parameters passed in......the way you reference that value when you add the watch will tell you how you need to reference it from the code. If add watch can't find it then adjust the reference till you get it.
This post has been edited by zaxbat: Mar 3 2018, 06:05 AM
Go to the top of the page
post Mar 3 2018, 08:39 AM

UA Admin
Posts: 34,109
Joined: 20-June 02
From: Newcastle, WA

When presented with an unexpected result like this, one very useful debug tool is to set a break point in the code and step through it, watching the values of different variables at each step. See where it goes off the track for you.
Go to the top of the page

Custom Search

RSSSearch   Top   Lo-Fi    14th December 2018 - 09:37 AM