Help with transfering data from Combo Box to Text Box (1 Viewer)

indian818

New member
Local time
Today, 19:45
Joined
Mar 30, 2021
Messages
15
Hi guys,

I have a combo box and a text box, I pick a data item from the drop down of the combo box, I want that the data item is transferred to the text box, I tried

Private Sub ComboBoxName_AfterUpdate()
TextBoxName.Value = ComboBoxName.Value
End Sub

and also tried

Private Sub ComboBoxName_AfterUpdate()
Me.TextBoxName= Me.ComboBoxName.Column(2)
End Sub

Both of them worked, but just worked partially, I mean when the data item of the combo box (a text) is too long, it cannot fully be transferred to the text box.
Could I please receive some help, thank in advance.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 12:45
Joined
Jul 9, 2003
Messages
13,575

missinglinq

AWF VIP
Local time
Today, 07:45
Joined
Jun 20, 2003
Messages
6,423
Textboxes default to 255 characters in v2007 (and I assume in future versions) but I believe that earlier versions defaulted to 50 characters.

What version are you using?

In Table Design, what is the Character count set to for your Field?

How many characters are present in the string to be transferred when all of them aren't?

Linq ;0)>
 

Isaac

Lifelong Learner
Local time
Today, 04:45
Joined
Mar 14, 2017
Messages
5,933
I just made a textbox bound to a table column with one record where the column has over 2,000 characters, and the bound textbox had no problem showing all characters. Can you upload a sample db
 

indian818

New member
Local time
Today, 19:45
Joined
Mar 30, 2021
Messages
15
Thank you all for your quick response, here my sample db
 

Attachments

  • Transfer data combobox2textbox.accdb
    1.6 MB · Views: 72

Isaac

Lifelong Learner
Local time
Today, 04:45
Joined
Mar 14, 2017
Messages
5,933
See attached
 

Attachments

  • Transfer data combobox2textbox.zip
    888 KB · Views: 233

indian818

New member
Local time
Today, 19:45
Joined
Mar 30, 2021
Messages
15
Great work man, it went smoothly, thank a lot.
When looking at the combo box, I came up with the idea of finding back the Client through the field Order, I mean when I type 1,2,3... (the Order of each Client) in the combo box, it will find back the record of the Client. I have a code:

Private Sub ComboBoxName_AfterUpdate()
' Find the record that matches the control.
Me.RecordsetClone.FindFirst "[Order] = " & Me![ComboBoxName]
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub

but don't know how to merge this code with the code in the sample db. Is that idea possible?
In addition, I wonder whether the combo box have the function of automatically dropping down when I type something?

Untitled.png


Untitled2.png
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 12:45
Joined
Jul 9, 2003
Messages
13,575
Looking at your requirement to select the FG options, I wondered if my my combo box alpha list product might do the job.


You are welcome to a free copy. Contact me for details on how to get it for free.
 

indian818

New member
Local time
Today, 19:45
Joined
Mar 30, 2021
Messages
15
Just did it

Private Sub ComboBoxName_AfterUpdate()
Me.TextBoxName.Value = DLookup("FieldName", "TableName", "FieldName2='" & Me.ComboBoxName.Column(1) & "'")
' Find the record that matches the control.
Me.RecordsetClone.FindFirst "[Order] = " & Me![ComboBoxName]
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub

It prioritizes finding the record while transferring data stop working.
 

Isaac

Lifelong Learner
Local time
Today, 04:45
Joined
Mar 14, 2017
Messages
5,933
Hmm.

Honestly - I don't usually use RecordsetClone.FindFirst, I simply set Me.Recordsource (in this type of situation). Therefore, I'm uncertain why your method isn't working - maybe someone else who does use this technique will know.
 

indian818

New member
Local time
Today, 19:45
Joined
Mar 30, 2021
Messages
15
Hmm.

Honestly - I don't usually use RecordsetClone.FindFirst, I simply set Me.Recordsource (in this type of situation). Therefore, I'm uncertain why your method isn't working - maybe someone else who does use this technique will know.

I think about an idea of using if code, like
if the number in the order < 100 then running the finding record code
if the number in the order > 100 then running the transferring data code
Is this idea possible? If it can, can you help me coding that?

I have another question, I have 2 command buttons, when I put their code together, they didn't work.
So I wonder whether we have a code like run a command button, I mean I will put this kind of code in the first command button, when I click on the first command button, it will finish with its function, then it automatically run the second command button, and I don't have to click on the second button myself. Can you help me with that too, many thanks in advance.
 

Isaac

Lifelong Learner
Local time
Today, 04:45
Joined
Mar 14, 2017
Messages
5,933
Personally, I don't recommend doing that.

In coding, there are all kinds of decisions to be made about scope, functionality, and location and usage of procedures (subs and functions), and events. If you get to the place where you find yourself writing code to force another object's Event to fire, in my opinion, it usually indicates you've made some mistakes in judgment about what code to put where. At least, that is what it has usually meant for me.

But the short answer is, why not just put everything you want "done" in the first button's click event? How does it make sense to write two button click events, and the first one calls the second one??
 
Last edited:

indian818

New member
Local time
Today, 19:45
Joined
Mar 30, 2021
Messages
15
Personally, I don't recommend doing that.

In coding, there are all kinds of decisions to be made about scope, functionality, and location and usage of procedures (subs and functions), and events. If you get to the place where you find yourself writing code to force another object's Event to fire, in my opinion, it usually indicates you've made some mistakes in judgment about what code to put where.

But the short answer is, why not just put everything you want "done" in the first button's click event? How does it make sense to write two button click events, and the first one calls the second one??
Thank for giving your opinion, I'll give it a careful thought.
 

indian818

New member
Local time
Today, 19:45
Joined
Mar 30, 2021
Messages
15
See attached
Hi, I encountered a problem, I placed it in the attached file, can you help me with that. Thank for your attention!
 

Attachments

  • Transfer data combobox2textbox.accdb
    1.6 MB · Views: 187

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:45
Joined
May 7, 2009
Messages
14,662
check and test
 

Attachments

  • Transfer data combobox2textbox.accdb
    2.1 MB · Views: 191

Users who are viewing this thread

Top Bottom