Solved

My code does not update the main file

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb6 programatically bring window to front 8 76
SSRS expression Issue finding a string 10 93
VBA filters 2 67
SQL VB connection works in one PC and doesn't in another 15 68
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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

820 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