when editing a record it doesnt save

Posted on 2006-04-25
Last Modified: 2010-05-18
I have a button in main.frm called edit with this

Private Sub cmdEdit_Click()
On Error Resume Next
Enabled = False
Load frmAccountDetails
frmAccountDetails.Populate (lstAccounts.ListIndex)
End Sub

and this in details.frm
Private Sub cmdOK_Click()
Dim FileNo As Integer
On Error Resume Next

FileNo = FreeFile
Open "Accounts.ini" For Append Shared As #FileNo
Print #FileNo, Text_Email.Text & ";" & Text_Passwd.Text & ";"
Close #FileNo

frmMain.Enabled = True
Unload frmAccountDetails
End Sub

Public Sub Populate(ByVal Record As Long)
'On Error Resume Next
    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
    'That has gone through the file till we have the correct record
    Text_Email = Split(strLine, ";")(0)
    Text_Passwd = Split(strLine, ";")(1)
End Sub

but is not saving the edited record!!! why is that?

this is the add button in main.frm that is working fine, but every time I add a record it doesnt show
until I reload the app..

Private Sub cmdAdd_Click()
On Error Resume Next
Enabled = False
End Sub
Question by:aplelois
    LVL 12

    Accepted Solution


    Try closing the file after you populate it. Also Write #fileno  instead of Print and see if that makes a difference. Also You might need a path to the Accounts.ini file.

    LVL 19

    Assisted Solution

    Perhaps consider using the GetPrivateProfile() API. It provides access to INI files.

    See the following article on editing INI files:

    Author Comment

    ok I just added Close #lngFHandle
    at the end of the populate, but now its making a new record!
    LVL 12

    Expert Comment

    I guess I was expecting that your call to populate the new record would append a new record and the cmdOK button would be the button to edit any changes to the populated values. At least that's what it appears the code is doing, but of course I have not tested it.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    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…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now