Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

edit listbox content

Posted on 2006-04-25
12
Medium Priority
?
192 Views
Last Modified: 2010-04-07
hello,
I have this in Form_Load()

    Dim lngFHandle As Long
    lngFHandle = FreeFile()
    Open "Accounts.ini" For Input As #lngFHandle
    Do
        Line Input #lngFHandle, strLine
        lstAccounts.AddItem Split(strLine, ";")(0)
    Loop Until EOF(lngFHandle)
    Close #lngFHandle

its working fine but right next to it I have a button called add/edit
when I select the email that I want to edit its only showing me the first
record in Accounts.ini, how can I make it so I can edit the one I select?
0
Comment
Question by:aplelois
  • 7
  • 4
12 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 16533973
Hi aplelois,

txtEdit.Text = lstAccounts.List(lstAccounts.ListIndex)

Will drop the selected item into the textbox txtEdit for you to do what you want with it.

Tim Cottee
0
 

Author Comment

by:aplelois
ID: 16534250
hum, where im I suppossed to locate that line ? in edit.frm or main.frm
cause the code I have is in main!
0
 

Author Comment

by:aplelois
ID: 16534262
this is my button

Private Sub cmdEdit_Click()
Enabled = False
EditDetails.Show
End Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 43

Expert Comment

by:TimCottee
ID: 16534269
aplelois,

That depends, you haven't really given very much information. All this does is show you how you can get the value of the currently selected item in the listbox. What you do with it then very much depends on your application which I obviously don't know.

Tim
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 16534283
aplelois,

That makes more sense, in that case what you need to do is pass this information to the editdetails form:

Private Sub cmdEdit_Click()
Enabled = False
Load EditDetails
EditDetails.txtEdit.Text = lstAccounts.List(lstAccounts.ListIndex)
EditDetails.Show
End Sub

This will open the form, set the value of txtEdit on the new form to the selected entry then show it.
Tim
0
 

Author Comment

by:aplelois
ID: 16534636
when I try to compile this line gets yellow
Private Sub cmdEdit_Click()

and it selects the (.txtEdit)

why is that?
0
 

Author Comment

by:aplelois
ID: 16534685
cause in the edit.frm I have this

Private Sub Form_Load()

Dim ff As Integer, Filename As String, s As String
Filename = "Accounts.ini"
ff = FreeFile
Open Filename For Binary Access Read Lock Read Write As #ff
s = Space$(LOF(ff))
Get #ff, , s
Close ff

Text_Email = Split(s, ";")(0)
'Text_Passwd = Split(s, ";")(1)

End Sub
0
 
LVL 8

Expert Comment

by:List244
ID: 16534745
Apleois he is expecting that you have a textbox on the form EditDetails named txtEdit which you wish
to contain the e-mail.  Change .txtEdit to the name of the textbox which should hold the value from the
listbox and the error will go away.

--Do not accept this comment for points.
0
 

Author Comment

by:aplelois
ID: 16534779
yes, I see that the errors goes aways but now its only showing the email and not the pass
I have two textbox in the edit.frm those are email and pass
this is what I have in account.txt email@domain.com;pass
so when I open the software I see only the email in the listbox, so If i click on edit
I go to the edit page.
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 2000 total points
ID: 16534814
aplelois,

Ok, txtEdit was my guess at your field. So I guess you need to use Text_Email instead. And possibly also need to add in the password. You can then do away with that code in the edit.frm as it will no longer be required.

The problem then is that you don't have the password to edit! Your code in form_load is what was always giving you the first record out of your accounts.ini file. You need to determine which record you want to get out, you can do this a number of ways, if the records are fixed length (which they probably aren't you can read record by record) or in your situation then it may be best to read line by line till you get the right one.

In edit.frm, remove the code from form_load, create a new PUBLIC sub as follows:

Public Sub Populate(ByVal Record As Long)
    Dim lngFHandle As Long
    Dim strLine As String
    lngFHandle = FreeFile()
    Open "Accounts.ini" For Input As #lngFHandle
    Dim intRecord As Long
    For intRecord = 0 To Record
       Line Input #lngFHandle,strLine
    Next
    'That has gone through the file till we have the correct record
    Text_Email = Split(strLine,";")(0)
    Text_Passwd = Split(strLine,";")(1)
End Sub

Then back in the main.frm change the sub to

Private Sub cmdEdit_Click()
Enabled = False
Load EditDetails
EditDetails.Populate(lstAccounts.ListIndex)
EditDetails.Show
End Sub

This will basically make the populate sub read through the records until it finds the one selected and then populate those fields.        


Tim
0
 

Author Comment

by:aplelois
ID: 16535090
thank you very much!!!
0
 

Author Comment

by:aplelois
ID: 16535098
could you please check http:Q_21826169.html maybe you could help me out in that one too!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question