Solved

My code does not update the main file

Posted on 2001-06-16
5
148 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:Ned_Kelly
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6199645
What problem do you get? Can you explain in detail?
0
 
LVL 6

Accepted Solution

by:
andyclap earned 100 total points
ID: 6200099
Isn't this the same as your other question?

incidentally,
  lngBal = Val(lngBal + mskDeposit.Text)

is a bit yucky, could try
  lngBal = lngBal + Val(mskDeposit.Text)

0
 

Author Comment

by:Ned_Kelly
ID: 6202972
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
0
 

Author Comment

by:Ned_Kelly
ID: 6210823
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
0
 
LVL 6

Expert Comment

by:andyclap
ID: 6210960
Thanks for the unexpected points!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Basic Excel Formatting error 4 102
Crystal reports - Formula Field code need assistance with code 17 72
How to Add / Edit Windows Menu 4 60
MsgBox 4 59
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…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

776 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