Text box with a "visible" value seems to be Null

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a main menu that opens different forms. Each button opens a form and
assigns a particular value to a text box in that form. So for example, this
is the code I have for one of those buttons:

DoCmd.OpenForm "frm_Pt_Info_IndividualOffice", acNormal
Forms!frm_Pt_info_individualoffice!txt_Header_Dpt = "Radiology"

When the form opens, I can see the "Radiology" text in the textbox. However,
when I try to assign the value of another textbox to the value of
txt_Header_Dpt I get an error message because, apparently, the value of
txt_Header_Dpt is null. This is what I used:

Me.DEPARTMENT.DefaultValue = Me.txt_Header_Dpt

I confirm the Null value of that text box by adding this line of code:

MsgBox "Value of dpt is " & Me.txt_Header_Dpt.Value

The only thing that I got when I run that code was "Value of dpt is "

Any ideas? Thanks!
 
My question is why if I can see the textbox with "Radiology" in it, when I
try to assign that same value to another textbox, I get a Null value? I need
to be able to assign the value of that text box to another object, like I
tried in this line of code:

Me.DEPARTMENT.DefaultValue = Me.txt_Header_Dpt

When I ran this, although I could see "Radiology" written in the
txt_Header_Dpt, the value of Me.txt_Header_Dpt was "empty"
 
There's a couple of possiblities here.

Is the cursor still in txt_Header_Dept when this happens?
If so, its Value may not have been updated yet.
To test this tab out to another control and try again.

If that is not the issue, is this:
a) a bound form
b) with no records
c) not even the new record, and
d) txt_Header_Dept is in the form header or footer?
Under these conditions, the Detail section of the form goes completely
blank. The boxes in the form header/footer are visible, but Access gets
confused about what they contain.

More info:
Incorrect display of data
at:
http://allenbrowne.com/bug-06.html
 
Hello Allen,

I think you just find the problem. My text box is in the form's header. I
opened the link that you gave me and it seems that the solution you propose
can be used when working with combo boxes. What would you suggest in this
case (a textbox)? is there any code to solve this?

Thanks for your help.
 
You are changing the *default* value of me.department, not the actual
contents. changing the default value does not affect anything you are
currently looking at. Try using just

Me.DEPARTMENT = Me.txt_Header_Dpt

John



My question is why if I can see the textbox with "Radiology" in it, when I
try to assign that same value to another textbox, I get a Null value? I need
to be able to assign the value of that text box to another object, like I
tried in this line of code:

Me.DEPARTMENT.DefaultValue = Me.txt_Header_Dpt

When I ran this, although I could see "Radiology" written in the
txt_Header_Dpt, the value of Me.txt_Header_Dpt was "empty"
What is your question?
[quoted text clipped - 21 lines]
 
If the conditions apply, then yes: it's worth using the workaround.

Simplest solution might be to allow the blank new record to show.
You can still prevent new records being added by cancelling the form's
BeforeInsert event.
 
Hi John,

The problem is not the DEPARTMENT field, the problem is the txt_Header_Dpt.
I can see that that textbox has RADIOLOGY in it, but in debug mode if I
placed the pointer on top of that part of the code, specifically on top of
txt_Header_Dpt, it shows "txt_Header_Dpt=empty", so the fact that I selected
the default value or the contents of the other field doesn't matter. I just
used the default value becaus I wanted to see the value that that other
object gets assigned with before I saved the record.

If you see why the textbox shows "empty" although I can see "RADIOLOGY" in
it, please let me know.

Thanks.





J_Goddard via AccessMonster.com said:
You are changing the *default* value of me.department, not the actual
contents. changing the default value does not affect anything you are
currently looking at. Try using just

Me.DEPARTMENT = Me.txt_Header_Dpt

John



My question is why if I can see the textbox with "Radiology" in it, when I
try to assign that same value to another textbox, I get a Null value? I need
to be able to assign the value of that text box to another object, like I
tried in this line of code:

Me.DEPARTMENT.DefaultValue = Me.txt_Header_Dpt

When I ran this, although I could see "Radiology" written in the
txt_Header_Dpt, the value of Me.txt_Header_Dpt was "empty"
What is your question?
[quoted text clipped - 21 lines]
Any ideas? Thanks!
 
Alejandro said:
The problem is not the DEPARTMENT field, the problem is the txt_Header_Dpt.
I can see that that textbox has RADIOLOGY in it, but in debug mode if I
placed the pointer on top of that part of the code, specifically on top of
txt_Header_Dpt, it shows "txt_Header_Dpt=empty", so the fact that I selected
the default value or the contents of the other field doesn't matter. I just
used the default value becaus I wanted to see the value that that other
object gets assigned with before I saved the record.

If you see why the textbox shows "empty" although I can see "RADIOLOGY" in
it, please let me know.


Doublle check your code, I rhink what you are describing
could be explained by having Dim txt_Header_Dpt
somewhere in your code.
 
Hi again, Marsh!

Unfortunately, that can't be the issue; I have not defined the first
variable in the whole database yet.

In short, what I need is like a second OpenArgs parameter that I could use
to transfer a value. I'm already using OpenArgs to assign the value of the
hospital field to that record and it works just fine. I would need something
similar to assign the value of the department.

This is the code for the button in the main menu that opens the form:

Private Sub cmd_Open_HospARad_Click()
DoCmd.OpenForm "frm_Pt_Info_IndividualOffice", acNormal, OpenArgs:="Hospital
A"
Forms!frm_Pt_Info_IndividualOffice!txt_Header_Dpt = "Radiology"
End Sub

This is the code for the load event for the form that is opened by the button:

Private Sub Form_Load()
DoCmd.GoToRecord , , acNewRec
Me.txt_Header_Hospital = Me.OpenArgs
Me.HOSPITAL.DefaultValue = """" & Me.OpenArgs & """"
Me.DEPARTMENT.DefaultValue = Me.txt_Header_Dpt 'this is the line of
code
'that doesn't work
End Sub

When that form opens I can see "Hospital A" in txt_Header_Hospital and
"Radiology" in txt_Header_Dpt. Both values are there in their text boxes. For
some reason, though, when I assign OpenArgs to Me.HOSPITAL.DefaultValue it
works just fine, but when I try to do the same with
Me.DEPARTMENT.DefaultValue (Me.DEPARTMENT.DefaultValue = Me.txt_Header_Dpt) I
get an error message because, according to Access, txt_Header_Dpt is empty,
never mind that I can actually read "Radiology" in that text box.

Hope that I explain what the problem is clearly, and that you can help me
out again. Thanks!!
 
Alejandro said:
Unfortunately, that can't be the issue; I have not defined the first
variable in the whole database yet.

In short, what I need is like a second OpenArgs parameter that I could use
to transfer a value. I'm already using OpenArgs to assign the value of the
hospital field to that record and it works just fine. I would need something
similar to assign the value of the department.

This is the code for the button in the main menu that opens the form:

Private Sub cmd_Open_HospARad_Click()
DoCmd.OpenForm "frm_Pt_Info_IndividualOffice", acNormal, OpenArgs:="Hospital
A"
Forms!frm_Pt_Info_IndividualOffice!txt_Header_Dpt = "Radiology"
End Sub

This is the code for the load event for the form that is opened by the button:

Private Sub Form_Load()
DoCmd.GoToRecord , , acNewRec
Me.txt_Header_Hospital = Me.OpenArgs
Me.HOSPITAL.DefaultValue = """" & Me.OpenArgs & """"
Me.DEPARTMENT.DefaultValue = Me.txt_Header_Dpt 'this is the line of
code
'that doesn't work
End Sub

When that form opens I can see "Hospital A" in txt_Header_Hospital and
"Radiology" in txt_Header_Dpt. Both values are there in their text boxes. For
some reason, though, when I assign OpenArgs to Me.HOSPITAL.DefaultValue it
works just fine, but when I try to do the same with
Me.DEPARTMENT.DefaultValue (Me.DEPARTMENT.DefaultValue = Me.txt_Header_Dpt) I
get an error message because, according to Access, txt_Header_Dpt is empty,
never mind that I can actually read "Radiology" in that text box.


Didn't we have a discussion before about the timing of
setting a vontrol value immediately after opening a form?
This seems like the same issue.

To pass multiple values in OpenArgs, you need to concatenate
all the values in the calling code:

OpenArgs:="Hospital A~Radiology"

and separate them out in the called code:

Dim Args As Variant
Args = Split(Me.OpenArgs, "~")
Me.txt_Header_Hospital = Args(0)
Me.HOSPITAL.DefaultValue = """" & Args(0) & """"
Me.txt_Header_Dpt = Args(1)
Me.DEPARTMENT.DefaultValue = """" & Args(1) & """"
 
Hi Marsh,

I honestly don't recall such discussion regarding the timing of setting
control values, but it is possible that I just missed it. If you don't mind,
I'd really appreciate if you could send me a couple of lines in this regard
so that I learned what my problem was.

Regarding the form itself, the split you showed me works perfectly, so
whether you send me a brief explanation of the variable issue or not, you
have already solved my problem, so thanks a lot!

Take care.

AP.
 
The OpenForm method initiates the opening of a form in an
asynchronous task at a lower priority than the VBA procedure
with the OpenForm line. This means that the code following
the OpenForm line can not rely on the state of the opening
form. The form object will exist, but the controls may not
be completely initialized or a record's data loaded. Some
of the timing depends on what the form has going on and some
of it depends on what else is going on in other applications
or in Windows. Other than using simple things like
DoCmd.Maximize, the reliable approach is to use OpenArgs (or
some other technique) to pass information to the new form so
it can perform the operations on itself in an appropriate
event when the controls are ready.
 
Thanks Marsh, I really appreciate it...

Marshall Barton said:
The OpenForm method initiates the opening of a form in an
asynchronous task at a lower priority than the VBA procedure
with the OpenForm line. This means that the code following
the OpenForm line can not rely on the state of the opening
form. The form object will exist, but the controls may not
be completely initialized or a record's data loaded. Some
of the timing depends on what the form has going on and some
of it depends on what else is going on in other applications
or in Windows. Other than using simple things like
DoCmd.Maximize, the reliable approach is to use OpenArgs (or
some other technique) to pass information to the new form so
it can perform the operations on itself in an appropriate
event when the controls are ready.
--
Marsh
MVP [MS Access]

I honestly don't recall such discussion regarding the timing of setting
control values, but it is possible that I just missed it. If you don't mind,
I'd really appreciate if you could send me a couple of lines in this regard
so that I learned what my problem was.

Regarding the form itself, the split you showed me works perfectly, so
whether you send me a brief explanation of the variable issue or not, you
have already solved my problem, so thanks a lot!
 
Back
Top