Solved

My code does not update the main file

Posted on 2001-06-16
5
146 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

707 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

20 Experts available now in Live!

Get 1:1 Help Now