0

This is not working.

Me.Textbox = Me.ListBox.ListCount

It say;

enter image description here

What code should I put into it? When I load the Form, it should display the count of the ListBox's items on the textbox.

0

2 Answers 2

2

The TextBox and ListBox are not the names of the variables, but oh the classes. When you instantiate an object of Textbox (or ListBox), VB gives it the name TexBox1 (or ListBox1). You can change this name in the properties window. I suppose what you have now are TextBox1 and ListBox1.

Me.Textbox1 = Me.ListBox1.ListCount
Sign up to request clarification or add additional context in comments.

1 Comment

I forgot that in my program, I put a label not a text box so I figured out that I had to put .caption if I use a label. Thank you!
1

There is nothing wrong with the syntax of your code. So the first thing that should be looked at is the names of your listbox and textbox. By default ms-access calls them list and text followed by a number. To find the assigned name go to their property and then the other tab and name of the control is at the top of the list.

Also make sure that you are running the code from the form's onload event. You may try the forms oncurrent event to see if it makes ant difence

2 Comments

I forgot that in my program, I put a label not a text box so I figured out that I had to put .caption if I use a label. Thank you!
That's where using prefix comes in handy. If you add lbl before every label name,txt before textbox name lst before listbox name etc... it's much easier to spot these little annoying errors when debugging your code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.