User form List box Column value to User form Text Box

JulianvO

New Member
Joined
Sep 9, 2022
Messages
38
Office Version
  1. 2021
Platform
  1. Windows
Greetings

FrmAdmin contains a Listbox - LboResult

LboResult has 8 columns. Columns 4 and 5 contain telephone numbers

Column 4 is a Mobile number: 0820000000

Column 5 is a landline number: 0110000000

Sheet2 has Columns Mobile and Telephone, which are custom formatted to accept the respective number formats.

The list box displays the respective numbers correctly.

However the user form TxtMobile.value does not display the leading zero.

Tried Me.TxtMobile.Value = Me.LboResult.Column(4) = Format(Me.TxtMobile.Value = "###-###-####")
Tried Me.TxtMobile.Value = Me.LboResult.Column(4) = Format(Me.TxtMobile.Value = "0")
Tried Me.TxtMobile.Value = Me.LboResult.Column(4) = Format(Me.TxtMobile.Value = "#0000000000")
Tried Me.TxtMobile.Value = Me.LboResult.Column(4) = Format(Me.TxtMobile.Value = "0*")

TxtMobile result is False.

Can someone assist me?
 
You missed trying this option, with 10 zeros:

VBA Code:
Me.TxtMobile.Value = Me.LboResult.Column(4) = Format(Me.TxtMobile.Value = "0000000000")
 
Upvote 0
I copied your example and didn't check it, it should be with a comma:
Rich (BB code):
Me.TxtMobile.Value = Format(Me.LboResult.Column(4), "0000000000")
 
Upvote 0
Solution
General knowledge:

1740423809202.png

I don't have the context of what you want to do, I assume that if you select a record from the listbox, you want to pass the data from column 4 to the textbox, then it would be like this:

VBA Code:
Private Sub LboResult_Click()
  Me.TxtMobile.Value = Format(Me.LboResult.Column(4), "0000000000")
End Sub
Notice how I am directly passing the value of the listbox, column 4 to the textbox.


The list box displays the respective numbers correctly.
But if you say that the listbox is displaying the phone correctly, then you should not need the Format function:

VBA Code:
Private Sub LboResult_Click()
  Me.TxtMobile.Value = Me.LboResult.Column(4)
End Sub


In the future, it would be easier to understand the problem, if you put your complete code.
🧙‍♂️
 
Upvote 0
Hi DanteAmor

Thanks for the feedback and the knowledge.
I attach screen shots of the relevant code / database.
As can be seen the mobile and telephone numbers aredisplayed correctly in the list box, but not in the relevant text boxes.

Screenshot 2025-02-24 213519.pngScreenshot 2025-02-24 213623.pngScreenshot 2025-02-24 213652.png

Thanks. Will definitely try your suggestions.
 
Upvote 0
Hi DanteAmor

The code - Me.TxtMobile.Value = Format(Me.LboResult.Column(4), "0000000000") - works like a charm.

Many thanks for your kind assistance.

Julian
 
Upvote 0
Julianv),

Please Note: In the future, when marking a post as the solution, please mark the post that contains the solution (not your own post acknowledging that some other post was the solution).
When a post is marked as the solution, it is then shown right underneath the original question so people viewing the question can easily see the question and solution in a single quick glance without having to hunt through all the posts.

I have updated this thread for you.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top