Which form property is synchronised with Me.Bookmark ?

  • Thread starter Thread starter Bram van Leur
  • Start date Start date
B

Bram van Leur

I've experimented and searched this newsgroup but I still don't have
the answer to this basic question. Although it should be simple I'll
try to explain it thoroughly in the hope others will find this answer.

If I have a textbox on my form which has a vba function as
ControlSource I want to access a recordset with it's cursor positioned
at the record that's being displayed (rendered).

So let's say I have the ControlSource of my control "=PrettyName()"
then
Public Function PrettyName()
PrettyName = Recordset.Fields("code")
End Function
prints a code of some record, but not always the record currently
displayed.

When I manually synchornize the Recordset property using the Bookmark
property
Public Function PrettyName()
Dim rs As ADODB.Recordset

Set rs = Me.Recordset
rs.Bookmark = Me.Bookmark

PrettyName = Recordset.Fields("code")
End Function
it does give the correct value.

But I feel there must be a must more elegant solution to this and not
have to add 4 lines of code for simply accessing a field value of the
current record.

How do I avoid synchronizing every time?
 
Your first example works for me, and always displays the value from the
correct record ...

Private Function TestFunc()
TestFunc = Recordset.Fields("TestDate")
End Function

I have to ask, though, why would you want to do this? It's just doing the
same thing as binding the control directly to the field, but a lot slower.
Perhaps there's more to this than you've told us?
 
Hi

Your function uses values from current recordset as calculation parameters?
Then send those parameters along with function call.
Something like this:

Public Function SayHallo(parForeName As String, parLastName As String) As
String
SayHallo="Hallo " & parForeName & " " & parLastName & "!"
End Function

Now, on form you have controls txtForeName and txtLastName, linked to
according fields in source table. The function call for 3rd, unbound control
will be:
=SayHallo([Me].[txtForeName], [Me].[txtLastName])
 
Arvi said:
Now, on form you have controls txtForeName and txtLastName, linked to
according fields in source table. The function call for 3rd, unbound control
will be:
=SayHallo([Me].[txtForeName], [Me].[txtLastName])

Well this is, more or less, the issue. I seem to need to have these 2
bounded controls while I'm not interested in displaying the values
seperately.

Is there I way I can pass fields from the recordset here without having
to synchornise the Recordset first?
 
Brendan said:
Your first example works for me, and always displays the value from the
correct record ...

I (maybe) forgot to mention some critical information, but it clearly
happens to me on a continuous form. This suggests it's not synchornized
by definition.
I have to ask, though, why would you want to do this?

Offcourse I want to apply some transformations on the value from the
recordset but I left that from the examples as it doesn't exactly matter
what I'm doing here.
 
Hi

As rule having some additional bounded controls on form practically don't
affect app's perfomance. I myself use such additional controls - with
Visible property set to False - quite frequently. What the user doesn't see,
doesn't bother him at all.


Arvi Laanemets


Bram said:
Arvi said:
Now, on form you have controls txtForeName and txtLastName, linked to
according fields in source table. The function call for 3rd, unbound control
will be:
=SayHallo([Me].[txtForeName], [Me].[txtLastName])

Well this is, more or less, the issue. I seem to need to have these 2
bounded controls while I'm not interested in displaying the values
seperately.

Is there I way I can pass fields from the recordset here without having
to synchornise the Recordset first?
 
Back
Top