selection in dropdown box should show a text in a textbox

lame_designer

Registered User.
Local time
Today, 07:13
Joined
Jan 31, 2006
Messages
14
I have a combo and a textbox in my form.
The name of the combo = cmbCaused by, the name of my textbox = txtDescription. One of the items in my combo box = Expeditors. When I select "expeditors" in my dropdown box I would like a text to appear in my textbox without having to linkt the textbox to a table (in other words use VB) Does anybody know how to do this ?
 
Last edited:
The simple way is to make your unbound text box have the same data as your combo box. Put this line of code in the After Update event of the combo box. Change the names to suit.

Me.Text2 = Me.Combo4

Don't have the same name for your text box as the command button.
 
I think that would show the combo-box-item in the textbox. This is not what I'm trying to achieve.
When people select "expeditor" in the combo-box it should show the following text in the textbox:

"Shipment has been rejected bla bla bla"

I also made a mistake in the names.. The correct names are:
dropdown box = cmbCaused by
textbox = txtDescription.
 
Last edited:
How about having a third and hidden column in your combo? When user makes a selection the value of the text box becomes the cmbCausedBy.Column(2)
 
Good idea.. gonna try that..
Thanks.. will let you know if it had the desired effect.. If I leave the extra column blanc and only fill out the "expeditor-record" it should work..

But since I'm just learning VB (inexperienced rookie I am) I would really appreciate it if somebody could tell me how i could achieve this in VB (give me a push in the right direction ;)
 
Last edited:
bit of a problem with that solution.. the textbox is bound to a table already..
 
lame_designer said:
bit of a problem with that solution.. the textbox is bound to a table already..

I've used this in the past and it worked for me:

1. You will still need to leave your textbox bound to that table.
2. The rowsource on your combobox should look like this:
SELECT YourTable.Causedby, YourTable.Description FROM YourTable; (or whatever ur query is.)

Then this should go to the Afterupdate of your combo.
Code:
Private Sub cmbCausedby_AfterUpdate()
    Dim Ssql As String
    Dim rs As DAO.Recordset

    If Me.NewRecord Then
        Ssql = "SELECT Description FROM YourTable where Causedby = " & Me!cmbCausedby.Value
        Set rs = CurrentDb.OpenRecordset(Ssql)
    Else
       'select the second column of the combo rowsource
	Me.txtDescription = Me.cmbCausedby.Column(1)
   End If
End Sub

Hope that helps
 
Thanks alot MS Lady, this works like a dream when an excisting record is changed, however when i create a clean form i get a debug error in the Ssql line.. The spaces used in the table names might cause this or the conversion from office 97. I'll create a form from scratch and figure it out..

Anyway, you are the greatest, thanks :) this was what i was looking for :)
 
Last edited:
Something is not right.. I get runtime error 3061
Not enough parameters.. Expected number is 1
It has a problem with this line :(

Set rs = CurrentDb.OpenRecordset(Ssql)
 
HEEELLLLPPPP (please)

I'm stuck and I'm desperate to find some help...

To get rid of the error i changed the code to : Me.txtDescription = Me.cmbCausedBy.Column(1)
This works nice without any errors however "the letter to customer" stops half way.. I suspect that you can only copy 255 characters this way... The description column is set to memo and the letter has about 500 characters.. Is there a way to display the full letter in my textbox ?

Does anybody know how to solve my problem ? (access is giving me headaches)
 
Last edited:
lame_designer said:
HEEELLLLPPPP (please)

I'm stuck and I'm desperate to find some help...

To get rid of the error i changed the code to : Me.txtDescription = Me.cmbCausedBy.Column(1)
This works nice without any errors however "the letter to customer" stops half way.. I suspect that you can only copy 255 characters this way... The description column is set to memo and the letter has about 500 characters.. Is there a way to display the full letter in my textbox ?

Does anybody know how to solve my problem ? (access is giving me headaches)

Hi lame_designer,

I have no idea. I'd suggest you open another thread stating this problem (since it's a new issue, different from the initial purpose and title of this thread), then it will be sure to catch people's attention and if anyone is familiar with your textbox issue u'd be sure to get the right help.

Also, don't forget to search the forum, or do a google keyword search e.g in your case, (access, textbox, character, 255 etc.) or
http://www.access-programmers.co.uk/forums/search.php?searchid=795044
something always comes up. I've become the google and forum search queen in the past couple of weeks :D very helpful :)
 

Users who are viewing this thread

Back
Top Bottom