Link to home
Start Free TrialLog in
Avatar of Ned_Kelly
Ned_KellyFlag for Australia

asked on

My code does not update the main file

My credit app has a main random file generated from the main form and transaction files that are generated on each transaction, from the transaction form.
Upon the pressing of the enter button of the transaction form, code is supposed to update the balance which is held on the main random form.
I'm having trouble achieving this.

The main form is frmCredit
frmCredit has mskBalance  using MaskEditBoxes.

The transaction form is frmTrans
frmTrans has mskDeposit and mskWithdrawal using MaskEditBoxes.


    'i = dlgCom.Filename
    frmCredit.mskBalance.Text = lngBal
    Open "A:\Data.dat" For Random As #1 Len = Len(udtCredit)
        If mskDeposit.Text <> "" Then
            udtCredit.curBalance = lngBal
            lngBal = Val(lngBal + mskDeposit.Text)
               i = Val(mskAccNum.Text)
               Put #1, i, udtCredit
        Else
            lngBal = Val(lngBal - mskWithdrawal.Text)
               Put #1, i, udtCredit
        End If
    Close #1

i was commented out during my trying to get it to work.
Ned
Avatar of Valliappan AN
Valliappan AN
Flag of India image

What problem do you get? Can you explain in detail?
ASKER CERTIFIED SOLUTION
Avatar of andyclap
andyclap
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ned_Kelly

ASKER

Hi Folks, the problem is that it doesn't do any thing.
The main form writes to a random access file, and stores data in it. One of those fields is mskBalance (a maskeditbox),
the other form is the transaction form which has two MaskEditBoxes, one called mskDeposit and the other mskWithdrawal. When the user fills in the deposit or withdrawal boxes and presses enter it should do two things.
One is to create a new file for every transaction and the other is to update the value in the random access file.
The random access file has eight fields;
Account Number
Last Name    
First Name    
Date of Birth    
Telephone number
Personal ID Number
Current Balance    
Current Date
The text files are created well but it wont update the value in the random file.
Ive had a couple of overflow errors but I have been able to get rid of those, not the best way most likely.

This is the whole of the cmdEnter if this will help at all,
I have also declared as public in the module all the fields that cross both forms.

Private Sub cmdEnter_Click()
    Dim strFileName As String
        Dim intUserResponse As Integer, intAccNum As Integer, Filename As String
        Dim i As Integer ', intDay As Integer, intMo As Integer, intYr As Integer
        Dim udtCredit As CreditStruc, lngBal As Long, intNew As Integer

       
     
        dlgCom.InitDir = "A:\Transact"
        dlgCom.Filename = Format(Now, "YYYYMMDD HHMMSS")

        If intUserResponse = vbCancel Then
            dlgCom.CancelError = True
        End If
        dlgCom.Filter = "Text Files(*.txt)|*.txt"
        dlgCom.ShowSave
        'mskAccNum.Text = Val(mskAccNum.Text) + 1

        'Close #i
            i = FreeFile
            For intNew = 1 To 30
            Open dlgCom.Filename For Output As #i
                Write #i, mskAccNum, mskDeposit, mskWithdrawal
            Close #i
            Next

ErrHandler:

    'i = dlgCom.Filename
    frmCredit.mskBalance.Text = i
    Open "A:\Data.dat" For Random As #1 Len = Len(udtCredit)
        If mskDeposit.Text <> "" Then

            udtCredit.lngBalance = lngBal
            lngBal = lngBal + Val(mskDeposit.Text)
                i = Val(mskDeposit.Text)
               Put #1, i, udtCredit
        Else
            lngBal = lngBal - Val(mskWithdrawal.Text)
               Put #1, i, udtCredit
        End If
    Close #1
    Call ClearFields
        mskAccNum.SelStart = 0
        mskAccNum.SelLength = Len(mskAccNum.Text)
        mskAccNum.SetFocus

End Sub

Hope this will help you to help me
Thankyou for your comments.
Ned
I'm accepting your answer as you picked up on a mistake that I had made in what was some bad code.  I have now changed it, and it works.

Many Thanks, for your help.
Ned
Thanks for the unexpected points!