Populating TextBox (1 Viewer)

David44Coder

Member
Local time
Today, 17:47
Joined
May 20, 2022
Messages
100
I hope this isn't too dumb a question, but something that really basic isn't working.

I have a Form with 2 text boxes, text2 is bound and text0 isn't.
My goal is to copy text2 to the unbound text box.
I thought it would be simple, but have failed with Me.Text0 = Me.Text2 in the Form Open Event, Load Event and Activate (which didn't appear to run)
Also tried text2.text after setting focus to it. Then DoEvents, Refresh, requery. Even Text2.After Update. Nothing has any effect
But a text0 d-click MsgBox Me!Text2 does display it.

What have a missed ? It must be blindlngly obvious but I can't see it.
 

silentwolf

Member
Local time
Yesterday, 22:47
Joined
Jun 12, 2009
Messages
384
Hi,

well it is as you said but I think you got the two mixed up.

Naming the textboxes a bit clearer might help also to get the code running.

Code:
Private Sub Form_Current()
    'txtNew=unbound textbox, txtBillC is bound'
    Me.txtNew = Me.txtBillC
End Sub
 

bob fitz

AWF VIP
Local time
Today, 06:47
Joined
May 23, 2011
Messages
4,459
...I thought it would be simple, but have failed with Me.Text0 = Me.Text2 ....
I believe it will work in the forms Current event but why would you want to duplicate the data like this? Just curious :unsure:
 

silentwolf

Member
Local time
Yesterday, 22:47
Joined
Jun 12, 2009
Messages
384
I believe it will work in the forms Current event but why would you want to duplicate the data like this? Just curious :unsure:
Yes I was not sure about that either :)
 

David44Coder

Member
Local time
Today, 17:47
Joined
May 20, 2022
Messages
100
Haha thanks very much everyone for setting me straight. Never even though about "Current". Too confused why it was failing.
As for why - the data in the table is not vbcrlf delimited, which I think is the sole text box requirement That that can't changed, can it ?
I will use better, names this was meant to be a quick try and see.
CJ_London that was a nice link, but can't help wondering if Form-Activate is meant to be the second event, a "Stop" there doesn't stop. And it didn't mention Form Load. I only recently found Form Load is bypassed if there is no record source.
 

Minty

AWF VIP
Local time
Today, 06:47
Joined
Jul 26, 2013
Messages
9,383
Form Load is where you should do anything that refers to data on the form, as before that no data is loaded.
After that, the current event is the most likely place.
Form open is very rarely the correct place for most code, unless it's to cancel opening the form.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 06:47
Joined
Feb 19, 2013
Messages
14,740
And it didn't mention Form Load.
it does

Opening and closing a form​

When you open a form, the following sequence of events occurs for the form:

Open
arrow
Load
arrow
Resize
arrow
Activate
arrow
Current

you can google each event to find out when they are triggered

if there is no datasource then there is nothing to trigger the load event
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:47
Joined
Feb 19, 2002
Messages
36,961
The Load event runs only ONCE. It is very unlikely that data based code would be useful here since the value in the field you checked in the first record could change with scrolling to the next record and the code would not run again.

Using the Current is always safe and will always work. Using the Load event works only under specific conditions.
 

Users who are viewing this thread

Top Bottom