• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

how to add value in listbox on click event

Nipendra


From MS help you will use something like:

[pre]
Code:
Private Sub CommandButton1_Click()
EntryCount = ListBox1.ListCount  + 1
ListBox1.AddItem (EntryCount & " - Selection")
End Sub
[/pre]
 
Thanks Hui,


could you please tell me if i have a textbox which is for employee id and i have a save button when i click on save button employee id by default take increasing number like at the first time when i click on the save button it should be 1 or 100 or else then whenever i will click on this save button the emplyee id should automataicly increase


Example-

Ename- "Nipendra" in textbox1.text

then click on save button then my database should be shows,

Eid=1 ot whatever and ename="Nipendra"


please help me if any idea


Regards

Nipendra
 
Nipendra


It may be better if you can upload a sample file so that people can see what you are doing and trying to achieve

Refer: http://chandoo.org/forums/topic/posting-a-sample-workbook


You can read the text boxes value by something like:

Code:
myValue = Textbox1.value + 1
 
Nipendra


A few Niceties first


I don't get paid to help out here, my efforts and the efforts of all the others who help out here is purely Voluntary

I don't appreciate being asked to "please now solve it "

If you want to pressure someone to help you you have every right to pay somebody.


Second, Your VBA requires access to a DB which you haven't provided and so the code can't be ran


Thirdly, You refer to TextBox1 above,. but the VBA Form in the file only has Textbox3 and Textbox4

Textbox3 is to the Right of the Employee Name and Textbox4 is underneath Employee name


At the moment when you click on Save (CommandButton1) it:

Sets abc = "insert into emaster(eid,ename) values(" & TextBox4.text & ",'" & TextBox3.text & "')"

Set rs = cn.Execute(abc)

Me.TextBox3 = Me.ListBox1.Column(0)

Me.TextBox4 = Me.ListBox1.Column(1)


Can you tell us what is meant to happen when you click on save on CommandButton1 (Save)
 
i am really sorry to use these scrawl words i really did'nt mean it. and i am not pressurise you any more.


i am sorry again


closed


thanks.
 
Nipendra


Were happy to help but you have to help us by providing sufficient data to help you
 
Hui thanks for forgive me,


here every thing is clear i can easly save my data to access table which name is emaster

by this same query string ""Sets abc = "insert into emaster(eid,ename) values(" & TextBox4.text & ",'" & TextBox3.text & "')"",


but now i dont want to give input in id textbox which is textbox4.text i want to automatic id creation that means when i click on save button then data should be saved by unique id

without enter anything in textbox4.text


i belive you may think about it, would really Applicable


thanks in advance

Warm Regards

Nipendra
 
As the DB is open

What about querying the DB

getting the maximum or last value for the ID field,

then add one to that
 
sorry i di'nt get you i am using ADODB connection to link with access database and insert query is working fine and as of now i am giving manually input to id field


Regards

Nipendra
 
When the ADODB connection is open why not query the database

Retrieve the last or maximum value from the ID field,


then use that to calculate the next Unique ID


eg: If the maximum ID value in the Database is Test101

try some code like this:

[pre]
Code:
MaxID = "Test101"
NewID = Left(MaxID, Len(MaxID) - 1) + Trim(Str(Val(Right(MaxID, 1)) + 1))
MsgBox NewID
[/pre]
 
Back
Top