Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

My code does not update the main file

Posted on 2001-06-16
5
Medium Priority
?
155 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 300 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

876 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