Display clicked item of listbox into Textbox + Go to that record

Display clicked item of listbox into Textbox + Go to that record

Page 1 of 1

6 Replies - 10731 Views - Last Post: 06 August 2010 - 03:21 AM Rate Topic: -----

#1 liquidninja  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 03-March 10

Display clicked item of listbox into Textbox + Go to that record

Posted 05 August 2010 - 02:20 AM

Hey guys,
I got a little problem here with Microsoft Access VBA. I'll try to explain it the best way i can.
I created a little form to add a code with a text to a certain database. It is also possible to delete or search Codes. I also added a small list to view all the codes with text that are in the database.
View screenshot: http://img517.images.../problemed.png/
I want to be able to click on the items of the list, this Code and Text gets placed automatically in the textboxes above. The code which i used is this:
Private Sub Listbox_Click()
     txtCode.Value = Listbox.Column(0)
     txtTekst.Value = Listbox.Column(1)
End Sub




Now, my problem is this: If i click on a code in the list, the record number does not change. So it WILL display the correct code, BUT if i click on 'Verwijderen', which means DELETE, it will delete the WRONG code. As you can see on the screenshot, R12 is the 1st record, and if i click R 13, the record number below will keep saying "1", while i want this to be "2".

I tried to add following code to solve this, but keeps generating error (probably because record number is wrong):
txtZoek.Value = Listbox.Column(0)
DoCmd.GoToControl ("txtCode")
Docmd.FindRecord Me.txtZoek



txtZoek is the textbox on top (used as search function, DOES work UNTIL a record is clicked)

I know this might sound a little complicated, so if any questions, just ask me, ill reply directly!

Thx!!

Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: Display clicked item of listbox into Textbox + Go to that record

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Display clicked item of listbox into Textbox + Go to that record

Posted 05 August 2010 - 03:57 AM

how do you delete them. so you mean that the text box that display the first column dont change? this i txtZoek right? why are you using txtZoek.Value = Listbox.Column(0) instead of text property?
Was This Post Helpful? 0
  • +
  • -

#3 liquidninja  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 03-March 10

Re: Display clicked item of listbox into Textbox + Go to that record

Posted 05 August 2010 - 04:12 AM

The delete button does this:
Private Sub btnDelete_Click
     DoCmd.RunCommand acCmdSelectRecord
     DoCmd.RunCommand acCmdDeleteRecord
Exit Sub



The issue is, that the record number at the bottom doesnt change. If i click for example R 12, it dispays R 12 + text in the textboxes. If I then click R 14 for example, the textboxes change, like they are supposed to, BUT the record number at the bottom doesnt change. I still says " 1 of 203 ", while it should say "3 of 203", since R 14 is record 3.
i have to use .Value because .Text doesn't work

Forget about txtZoek at a second (the textfield on top),
as soon as the record number issue is solved, i will figure this one out.
Was This Post Helpful? 0
  • +
  • -

#4 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Display clicked item of listbox into Textbox + Go to that record

Posted 05 August 2010 - 06:17 AM

sorry dude i cant think of anything right now. today is a hell at my work i will try to think of something when i come back home.
Was This Post Helpful? 0
  • +
  • -

#5 liquidninja  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 03-March 10

Re: Display clicked item of listbox into Textbox + Go to that record

Posted 05 August 2010 - 06:23 AM

haha okay :) thanks! I'm at work too, holiday job..access programming. Almost everything done, except this. I just cant get it to work!
I can mail u the database if you like. Its pretty big though.
Was This Post Helpful? 0
  • +
  • -

#6 liquidninja  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 03-March 10

Re: Display clicked item of listbox into Textbox + Go to that record

Posted 06 August 2010 - 03:19 AM

okay i solved it lol.. Just had to delete
txtCode.Value = Listbox.Column(0)
txtTekst.Value = Listbox.Column(1)
and let the search function do the job so ALL i needed was this:
    txtZoek.Value = Listbox.Column(0)  
    DoCmd.GoToControl ("txtCode")  
    DoCmd.FindRecord Me.txtZoek 


omfg :D
Was This Post Helpful? 2
  • +
  • -

#7 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Display clicked item of listbox into Textbox + Go to that record

Posted 06 August 2010 - 03:21 AM

glad you made it :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1