Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refresh, requery, repaint to populate a textbox on a form from a value on seperate form on load?

Status
Not open for further replies.

MrMode

Technical User
Aug 28, 2003
195
0
0
GB
I have a form with a command button on it.

Then onClick event pushes a value to an unbound text box on a separate form.

Code:
' 1.Open second form 

    DoCmd.OpenForm "frmB"
    
' 2. Set the default value of the text box on the form
    
    Forms.frmB.Text45 = Me.PLID

When frmB opens, a listbox uses the value in Text45 as criteria

Code:
Private Sub Form_Load()

    With Me.List41
    .RowSource = _
        "SELECT * " & _
        "FROM Table1 " & _
        "WHERE Table1.PLID = " & Me.Text45
    End With
    
End Sub

However, even though I can see a value in Text45 it is evaluated as NULL by the code firing OnLoad...

I have tried different methods to force the form to pick up the value and populate the listbox

Me.Refresh
Me.Repaint
Me.Requery
Me.Recalc

but none of them are working. The listbox only populates if I open the form in design view and reopen it normally.

I have seen some comments about OpenArgs (I am not familiar with how to use this) but wondered if there was something simple I was missing?
 
This code is not correct.
Forms.frmB.Text45 = Me.PLID
either
Forms!frmB.text45
or
Forms("FrmB").text45

Forms is a collection with an index of "frmB". FrmB is not a property of Forms.
 
Quick reply, thanks!

Hmm, neither are working, it still shows me a value in the text box but is evaluating it as null - i.e. the listbox is empty and debug.print me.list41 NULL
 
Apologies, I realised I did not make it clear that the second form is unbound

What I have done is change the form so that it is bound to Table1 and added the field PLID.

I then changed the code that fires onClick to:

Code:
  DoCmd.OpenForm "FrmB", acNormal, "", "[PLID]=" & Me.PLID, , acNormal

And the listbox fires.

However, if anyone can figure out where I place the code to populate the listboxes when the form is unbound, that would be most helpful. It seems to me that the OnClick event is sending the value to the text box, but the form is not acknowledging it is there as all the code is firing OnLoad, is there some other way of allowing the textbox to verify it has a value and then step through the listbox population code?
 
If you put some breaks points in your code, you will find this is the order of your logic

When you assign the value in frmA to your frmB.Text45 (terrible name for the control, BTW. So is List41), in order to have this control available in frmB, your application first have to Load frmB (which runs your Select statement, nothing in Text45 yet.).
Once frmB is loaded, Text45 gets the value. Process is done.


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Thanks Andy

Yes, awful names they will change once I get everything working.

I understand what you are saying, so where would I execute the list population code if I have to wait for the form to load in order to have the value available?
 
There is several ways to do this. I probably would do it using the openArgs argument of the openform method. Pass in the PLID as an argument.
 
OK, thanks. I will go away and read up on openArgs :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top