Unbound TextBox

D

DS

I have a unbound textBox on an unbound form. How do you requery the
unbound textBox.
I know requery works for a listbox or a combo but how do you get the
unbound textbox to show the new information? I tried refresh to no avail.
Thanks
DS
 
R

Rick Brandt

DS said:
I have a unbound textBox on an unbound form. How do you requery the
unbound textBox.
I know requery works for a listbox or a combo but how do you get the
unbound textbox to show the new information? I tried refresh to no
avail. Thanks
DS

Me!TextBoxName.Requery should work. You could also try Me.Recalc.
 
D

DS

Rick said:
Me!TextBoxName.Requery should work. You could also try Me.Recalc.
Sorry Rick. The Unbound Textbox come from an unbound listbox. So I
requeried the Listbox and now I need to set the unbound t ext box to the
selected record in the listbox. I tried this.

Forms!MenuCreator!ListFri.Selected = Forms!MenuCreator!TxtMenu
but this doesn't seem to grab the record from the TxtMenu. It just goes
to the first record. Any way of getting the listbox to select the record
based on the TxtMenu field?
Thanks
DS
 
R

Rick Brandt

DS said:
Sorry Rick. The Unbound Textbox come from an unbound listbox. So I
requeried the Listbox and now I need to set the unbound t ext box to
the selected record in the listbox. I tried this.

Not clear here. If you Requery the ListBox then it will no longer have any row
selected. If you have already made a selection in the list why are you
requerying?
Forms!MenuCreator!ListFri.Selected = Forms!MenuCreator!TxtMenu
but this doesn't seem to grab the record from the TxtMenu. It just
goes to the first record. Any way of getting the listbox to select
the record based on the TxtMenu field?

More non-clarity. Are you trying to get the ListBox to take on the value
entered in the TextBox or are you trying to get the TextBox to display according
to the selection in the list?

To assign the value of a ListBox you need to use its Value property, not its
Selected property. In cases where the Selected property is being used you need
to supply an index number to be set to either True or False. You cannot assign
it to a value directly.

EX: This will select the second row in your ListBox

Forms!MenuCreator!ListFri.Selected(1) = True
 
D

DS

Rick said:
Not clear here. If you Requery the ListBox then it will no longer have any row
selected. If you have already made a selection in the list why are you
requerying?




More non-clarity. Are you trying to get the ListBox to take on the value
entered in the TextBox or are you trying to get the TextBox to display according
to the selection in the list?

To assign the value of a ListBox you need to use its Value property, not its
Selected property. In cases where the Selected property is being used you need
to supply an index number to be set to either True or False. You cannot assign
it to a value directly.

EX: This will select the second row in your ListBox

Forms!MenuCreator!ListFri.Selected(1) = True
Thanks Rick,
Almost there. The Listbox requeries, It then goes to the selected
record. The ony problem now is getting the unbound textbox to display
the new start time.
Thank you for your help.
DS
 
R

Rick Brandt

DS said:
Thanks Rick,
Almost there. The Listbox requeries, It then goes to the selected
record.

What "...goes to the selected record"? The ListBox? The Form?
The ony problem now is getting the unbound textbox to display
the new start time.

Where is the value for the new start time supposed to come from?

I am having a very difficult time understanding what you want. If what you want
is for the TextBox to display a value from the ListBox then this depends on a
few things...

Does the ListBox have multiple columns (including hidden ones)?

If so, do you want the TextBox to grab the value of the bound column or some
other column? Getting the value of the bound column is the same as getting it
from any other control...

Me!TextBoxName = Me!ListBoxName

If you want some other column then...

Me!TextBoxName = Me!ListBoxName.Column(n)

....where 'n' is the zero-based ordinal column position.
 
D

DS

Rick said:
What "...goes to the selected record"? The ListBox? The Form?




Where is the value for the new start time supposed to come from?

I am having a very difficult time understanding what you want. If what you want
is for the TextBox to display a value from the ListBox then this depends on a
few things...

Does the ListBox have multiple columns (including hidden ones)?

If so, do you want the TextBox to grab the value of the bound column or some
other column? Getting the value of the bound column is the same as getting it
from any other control...

Me!TextBoxName = Me!ListBoxName

If you want some other column then...

Me!TextBoxName = Me!ListBoxName.Column(n)

...where 'n' is the zero-based ordinal column position.
Ok Rick,
Lets start from the begining in all fairness to you.
I have an unbound listbox. I also have an unbound
field called TxtStart. Whenever I click on the unbound listbox it sets
the value of the TxtStart textbox. It also sets the value of TxtMenu.
Now to edit the TxtStart field I openanother form and select a time.
Using SQL to update the record. After closing this form I need the
Unbound listbox to go to the record (Menu) that is still in TxtMenu, I
also need the TxtStart field to update to the new Start Time. I hope
this is cleared. Once agian thank you for your help.
DS
 
D

DS

DS said:
Ok Rick,
Lets start from the begining in all fairness to you.
I have an unbound listbox. I also have an unbound
field called TxtStart. Whenever I click on the unbound listbox it sets
the value of the TxtStart textbox. It also sets the value of TxtMenu.
Now to edit the TxtStart field I openanother form and select a time.
Using SQL to update the record. After closing this form I need the
Unbound listbox to go to the record (Menu) that is still in TxtMenu, I
also need the TxtStart field to update to the new Start Time. I hope
this is cleared. Once agian thank you for your help.
DS
Basically I need to select a record in a listbox based on a textbox.
Thanks
DS
 
D

DS

DS said:
Basically I need to select a record in a listbox based on a textbox.
Thanks
DS
Hi Rick,
This ended up working, something I found from way back. Why it works, I
don't know. (I'd like to!)
Thanks
DS

For i = 0 To Forms!MenuCreator!ListSun.ListCount - 1
If Forms!MenuCreator!ListSun.Column(2, i) =
Forms!MenuCreator.TxtMenu Then
Forms!MenuCreator!ListSun.Selected(i) = True
End If
Next
Forms!MenuCreator!TxtStart =
Format(Forms!MenuCreator!ListSun.Column(4), "h:nn AM/PM")
DoCmd.Close acForm, "AMPM"
 
R

Rick Brandt

DS said:
Hi Rick,
This ended up working, something I found from way back. Why it
works, I don't know. (I'd like to!)
Thanks
DS

For i = 0 To Forms!MenuCreator!ListSun.ListCount - 1
If Forms!MenuCreator!ListSun.Column(2, i) =
Forms!MenuCreator.TxtMenu Then
Forms!MenuCreator!ListSun.Selected(i) = True
End If
Next
Forms!MenuCreator!TxtStart =
Format(Forms!MenuCreator!ListSun.Column(4), "h:nn AM/PM")
DoCmd.Close acForm, "AMPM"

Well, this code loops through all of the rows in your ListBox until it finds the
row where the third column matches your TxtMenu value. It then selects that row
by setting the Selected property of that row to True. Once selected, the value
from the fifth column of that row is retrieved and copied into TxtStart.

Not a terribly efficient way to do it unless the number of rows in the list is
small. I would add a line of code to break out of the loop once the desired row
is found. As it is currently written it is looping through all of the rows in
the list (even those after it has already found the matching one). This would
be accomplished by adding "Exit For" to the code.
 
D

DS

Rick said:
Well, this code loops through all of the rows in your ListBox until it finds the
row where the third column matches your TxtMenu value. It then selects that row
by setting the Selected property of that row to True. Once selected, the value
from the fifth column of that row is retrieved and copied into TxtStart.

Not a terribly efficient way to do it unless the number of rows in the list is
small. I would add a line of code to break out of the loop once the desired row
is found. As it is currently written it is looping through all of the rows in
the list (even those after it has already found the matching one). This would
be accomplished by adding "Exit For" to the code.
Thank yu Rick for the detailed explanation. I would like to add the
Exit For to make it more efficient. Where exactly would I place it?
Thank you
DS
 
R

Rick Brandt

DS said:
Thank yu Rick for the detailed explanation. I would like to add the
Exit For to make it more efficient. Where exactly would I place it?
Thank you
DS

It would be the last line of code inside the If-Then block (the true part).
 
D

DS

Rick said:
It would be the last line of code inside the If-Then block (the true part).

Rick Like This? Thanks DS
For i = 0 To Forms!MenuCreator!ListSun.ListCount - 1
If Forms!MenuCreator!ListSun.Column(2, i) =
Forms!MenuCreator.TxtMenu Then
Forms!MenuCreator!ListSun.Selected(i) = True
Exit For
End If
Next
 
R

Rick Brandt

DS said:
Rick Like This? Thanks DS
For i = 0 To Forms!MenuCreator!ListSun.ListCount - 1
If Forms!MenuCreator!ListSun.Column(2, i) =
Forms!MenuCreator.TxtMenu Then
Forms!MenuCreator!ListSun.Selected(i) = True
Exit For
End If
Next

That should do it.
 

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

Top