Nothing shows in text box (1 Viewer)

kirkm

Registered User.
Local time
Today, 16:04
Joined
Oct 30, 2008
Messages
1,257
I must be making some very basic error with this, but it's got me beat.
There's text boxes txtCode and txtCat on My Form populated so
Code:
    Form_frmExportExcel2.TheCat = Me!Cat
    Form_frmExportExcel2.TheCode = Me!Code
    DoCmd.OpenForm "frmExportExcel2", acNormal
Then in the Form there's
Code:
Public Property Let TheCode(v As String)
    txtCode = v
End Property

Public Property Let TheCat(v As String)
    txtCat = v
End Property
I can step through and see the values being assigned. After the Form opens I can debug.? form_frmExportexcel2.txtCode and the right things show up.

But why is there nothing in the text boxes ?
Thanks..
 

June7

AWF VIP
Local time
Yesterday, 20:04
Joined
Mar 9, 2014
Messages
5,466
Are you building a custom class? I have never seen a procedure like that.

Why are you using code to populate textboxes with data from fields? Why not bind controls to fields?
 

kirkm

Registered User.
Local time
Today, 16:04
Joined
Oct 30, 2008
Messages
1,257
To bind it to a control, it would need to specify which record. It's already at that record when it fires the click event that opens the form. Although it isn't working and I wonder why ? I should work, I think ?
 

June7

AWF VIP
Local time
Yesterday, 20:04
Joined
Mar 9, 2014
Messages
5,466
What? Why do you need to specify a record in order to bind controls to fields?

What do you mean by "It's already at that record" - where?

Bind controls then apply filter to form or report if you want to view only a specific record.
 

kirkm

Registered User.
Local time
Today, 16:04
Joined
Oct 30, 2008
Messages
1,257
It's just how I do things June, a bit overkill to go into greater detail.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 14:04
Joined
Jan 20, 2009
Messages
12,851
I must be making some very basic error with this, but it's got me beat.
There's text boxes txtCode and txtCat on My Form populated so
Code:
    Form_frmExportExcel2.TheCat = Me!Cat
    Form_frmExportExcel2.TheCode = Me!Code
    DoCmd.OpenForm "frmExportExcel2", acNormal

Your basic error is you are referring to the form via its module. This should never be done.

A hidden instance is being opened by the module reference. The form you open with the OpenForm Method is a different instance.
 

kirkm

Registered User.
Local time
Today, 16:04
Joined
Oct 30, 2008
Messages
1,257
Although I thought I'd tried this already, putting the OpenForm Command first has fixed the problem, the text boxes are now populated..
What would you change so it didn't open a hidden instance ?
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 14:04
Joined
Jan 20, 2009
Messages
12,851
What would you change so it didn't open a hidden instance ?

Forms should always be referred to via a Collection. If it is loaded it will be in the Forms Collection.

Code:
Forms!formname
All forms, loaded or not, can be referred to via the all AllForms Collection.
Code:
CurrentProject.AllForms.formname
The IsLoaded property can be tested to determine if a form is loaded.
Code:
CurrentProject.AllForms.formname.IsLoaded
 

kirkm

Registered User.
Local time
Today, 16:04
Joined
Oct 30, 2008
Messages
1,257
Thanks Galaxiom I didn't know that. Have changed to
Code:
    DoCmd.OpenForm "frmExportExcel2", acNormal
'    Form_frmExportExcel2.TheCat = Me!Cat
'    Form_frmExportExcel2.TheCode = Me!Code
'    Form_frmExportExcel2.Action
    
    Forms!frmExportExcel2.TheCat = Me!Cat
    Forms!frmExportExcel2.TheCode = Me!Code
    Forms!frmExportExcel2.Action
 

Users who are viewing this thread

Top Bottom