Text box visibility

S

Sandy

On my form "Finalise Jobs" i have (amongst other controls), "Date ready" -
txtDateReady, "Date Required" - txtDateRequired, "WhyDelayed" -
txtWhyDelayed, and a search Combo Box - cboSearch.

The following code is attached to txtDateReady :-

Private Sub txtDateReady_AfterUpdate()
If txtDateReady > Forms![Finalise Jobs].txtDateRequired Then
Me.lblWhyDelayed.Visible = True
Me.txtWhyDelayed.Visible = True

Else
Me.lblWhyDelayed.Visible = False
Me.txtWhyDelayed.Visible = False
End If
End Sub

and the following to the form :-

Private Sub Form_Open(Cancel As Integer)
If txtDateReady > Forms![Finalise Jobs].txtDateRequired Then
Me.lblWhyDelayed.Visible = True
Me.txtWhyDelayed.Visible = True

ElseIf txtDateReady = "" Then
Me.lblWhyDelayed.Visible = False
Me.txtWhyDelayed.Visible = False

Else
Me.lblWhyDelayed.Visible = False
Me.txtWhyDelayed.Visible = False
End If
End Sub

and the following on the combo box :-

Private Sub cboSearch_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[JobID] = " & Str(Nz(Me![cboSearch], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

My question :-
When the value in txtDateReady is typed in as greater than that in
txtDateRequired then the txtWhyDelayed is visible. Fine. However when I
search in cboSearch and the record that is shown is known to have a comment
in txtWhyDelayed it is not visible.
What code placed where would force the txtWhyDelayed to be visible when the
txtDateReady is later than txtDateRequired, in other words when a comment
already exists in txtWhyDelayed.

Hope this makes sense
Sandy
 
D

Dale Fye

Sandy,

Move the code from the Open event to the Current event.

Also, I keep my code shorter, and find it easier to read to do the
following. It's a preference thing, but thought I'd mention it.

Private Sub txtDateReady_AfterUpdate()

Dim bDisplayWhy as boolean

bDisplayWhy = (me.txtDateReady > me.txtDateRequired)
me.lblWhyDelayed.visible = bDisplayWhy
me.txtWhyDelayed.visible = bDisplayWhy

End Sub

I'm not sure why you are using the str( ) function in your findfirst?
Also, when you use the FindFirst method, I recommend that you use the
NoMatch method rather than If Not rs.eof to determine whether to set the
bookmark. Something like:

rs.FindFirst "[JobID] = " & NZ(me.cboSearch, 0)
If rs.noMatch then
msgbox "No match found"
else
me.bookmark = rs.bookmark
endif

Also, as good coding practice, you should explicitly release your recordset
immediately after the above.

rs.close
set rs = nothing

HTH
Dale
 
S

Sandy

Hi Dale

I have moved the code as you suggested and it now works fine.

The following code :-

Private Sub cboSearch_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[JobID] = " & Str(Nz(Me![cboSearch], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

was produced by the wizard when I inserted the combo box onto my form and
selected the "Search for a record......" option. I don't fully understand it
i'm afraid, but the way it works is a list of surnames is dropped down in
the combo box and the required name is selected which then pulls up all that
persons details - so I can't see a situation arising where the record won't
be found.

Also I have replaced my cumbersome code with your more elegant version in
txtDateReady_AfterUpdate and naturally it works fine.
I presume the first line is saying something like "The situation is True
when txtDateReady > txtDateRequired"

Many Thanks Dale
Sandy

Dale Fye said:
Sandy,

Move the code from the Open event to the Current event.

Also, I keep my code shorter, and find it easier to read to do the
following. It's a preference thing, but thought I'd mention it.

Private Sub txtDateReady_AfterUpdate()

Dim bDisplayWhy as boolean

bDisplayWhy = (me.txtDateReady > me.txtDateRequired)
me.lblWhyDelayed.visible = bDisplayWhy
me.txtWhyDelayed.visible = bDisplayWhy

End Sub

I'm not sure why you are using the str( ) function in your findfirst?
Also, when you use the FindFirst method, I recommend that you use the
NoMatch method rather than If Not rs.eof to determine whether to set the
bookmark. Something like:

rs.FindFirst "[JobID] = " & NZ(me.cboSearch, 0)
If rs.noMatch then
msgbox "No match found"
else
me.bookmark = rs.bookmark
endif

Also, as good coding practice, you should explicitly release your
recordset
immediately after the above.

rs.close
set rs = nothing

HTH
Dale
--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



Sandy said:
On my form "Finalise Jobs" i have (amongst other controls), "Date
ready" -
txtDateReady, "Date Required" - txtDateRequired, "WhyDelayed" -
txtWhyDelayed, and a search Combo Box - cboSearch.

The following code is attached to txtDateReady :-

Private Sub txtDateReady_AfterUpdate()
If txtDateReady > Forms![Finalise Jobs].txtDateRequired Then
Me.lblWhyDelayed.Visible = True
Me.txtWhyDelayed.Visible = True

Else
Me.lblWhyDelayed.Visible = False
Me.txtWhyDelayed.Visible = False
End If
End Sub

and the following to the form :-

Private Sub Form_Open(Cancel As Integer)
If txtDateReady > Forms![Finalise Jobs].txtDateRequired Then
Me.lblWhyDelayed.Visible = True
Me.txtWhyDelayed.Visible = True

ElseIf txtDateReady = "" Then
Me.lblWhyDelayed.Visible = False
Me.txtWhyDelayed.Visible = False

Else
Me.lblWhyDelayed.Visible = False
Me.txtWhyDelayed.Visible = False
End If
End Sub

and the following on the combo box :-

Private Sub cboSearch_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[JobID] = " & Str(Nz(Me![cboSearch], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

My question :-
When the value in txtDateReady is typed in as greater than that in
txtDateRequired then the txtWhyDelayed is visible. Fine. However when I
search in cboSearch and the record that is shown is known to have a
comment
in txtWhyDelayed it is not visible.
What code placed where would force the txtWhyDelayed to be visible when
the
txtDateReady is later than txtDateRequired, in other words when a comment
already exists in txtWhyDelayed.

Hope this makes sense
Sandy
 
D

Dale Fye

Sandy,

1. The wizard does not always produce the most elegant code, but it is
functional. Did not realize it was producing this code. Although it works,
it provides a bad example for when you want to do a free text input search.
It also will only work if you have the combo boxes "LimitToList" property set
to true.

I also prefer to provide the user with feedback when there is no match

2. Yes, by setting a boolean value equal to a test, the "test" to the right
of the equal sign is evaluated as either true or false, and then set to this
boolean value.

Glad I could help.
--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



Sandy said:
Hi Dale

I have moved the code as you suggested and it now works fine.

The following code :-

Private Sub cboSearch_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[JobID] = " & Str(Nz(Me![cboSearch], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

was produced by the wizard when I inserted the combo box onto my form and
selected the "Search for a record......" option. I don't fully understand it
i'm afraid, but the way it works is a list of surnames is dropped down in
the combo box and the required name is selected which then pulls up all that
persons details - so I can't see a situation arising where the record won't
be found.

Also I have replaced my cumbersome code with your more elegant version in
txtDateReady_AfterUpdate and naturally it works fine.
I presume the first line is saying something like "The situation is True
when txtDateReady > txtDateRequired"

Many Thanks Dale
Sandy

Dale Fye said:
Sandy,

Move the code from the Open event to the Current event.

Also, I keep my code shorter, and find it easier to read to do the
following. It's a preference thing, but thought I'd mention it.

Private Sub txtDateReady_AfterUpdate()

Dim bDisplayWhy as boolean

bDisplayWhy = (me.txtDateReady > me.txtDateRequired)
me.lblWhyDelayed.visible = bDisplayWhy
me.txtWhyDelayed.visible = bDisplayWhy

End Sub

I'm not sure why you are using the str( ) function in your findfirst?
Also, when you use the FindFirst method, I recommend that you use the
NoMatch method rather than If Not rs.eof to determine whether to set the
bookmark. Something like:

rs.FindFirst "[JobID] = " & NZ(me.cboSearch, 0)
If rs.noMatch then
msgbox "No match found"
else
me.bookmark = rs.bookmark
endif

Also, as good coding practice, you should explicitly release your
recordset
immediately after the above.

rs.close
set rs = nothing

HTH
Dale
--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.



Sandy said:
On my form "Finalise Jobs" i have (amongst other controls), "Date
ready" -
txtDateReady, "Date Required" - txtDateRequired, "WhyDelayed" -
txtWhyDelayed, and a search Combo Box - cboSearch.

The following code is attached to txtDateReady :-

Private Sub txtDateReady_AfterUpdate()
If txtDateReady > Forms![Finalise Jobs].txtDateRequired Then
Me.lblWhyDelayed.Visible = True
Me.txtWhyDelayed.Visible = True

Else
Me.lblWhyDelayed.Visible = False
Me.txtWhyDelayed.Visible = False
End If
End Sub

and the following to the form :-

Private Sub Form_Open(Cancel As Integer)
If txtDateReady > Forms![Finalise Jobs].txtDateRequired Then
Me.lblWhyDelayed.Visible = True
Me.txtWhyDelayed.Visible = True

ElseIf txtDateReady = "" Then
Me.lblWhyDelayed.Visible = False
Me.txtWhyDelayed.Visible = False

Else
Me.lblWhyDelayed.Visible = False
Me.txtWhyDelayed.Visible = False
End If
End Sub

and the following on the combo box :-

Private Sub cboSearch_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[JobID] = " & Str(Nz(Me![cboSearch], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

My question :-
When the value in txtDateReady is typed in as greater than that in
txtDateRequired then the txtWhyDelayed is visible. Fine. However when I
search in cboSearch and the record that is shown is known to have a
comment
in txtWhyDelayed it is not visible.
What code placed where would force the txtWhyDelayed to be visible when
the
txtDateReady is later than txtDateRequired, in other words when a comment
already exists in txtWhyDelayed.

Hope this makes sense
Sandy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Run code when text box content deleted 2
Code Problem 4
Calendar Control 1
Calendar control part 2 7
One calendar instead of two? 4
LIKE search help needed 3
Form code runs too quickly 4
Answer for Tammy (code) 1

Top