Solved

I cant write to the file

Posted on 2001-06-15
7
145 Views
Last Modified: 2010-05-02
Hi folks, my cmdEnter code used to write to the file very well, and then I did some testing and code changing in the application and now it wont write.

Am I losing it or what.

Private Sub cmdEnter_Click()
    Const conMsg As String = "Account numbers range from 1 to 30."
    Const conBtns As Integer = vbOKOnly + vbInformation _
                + vbDefaultButton1 + vbApplicationModal
    Dim udtCredit As CreditStruc
    Dim strFilename As String, i As Integer
    Dim intUserResponse As Integer, recordLength As Long
    Dim intAccNum As Integer, x As Integer
   
        On Error GoTo errHandler

        intAccNum = Val(mskAccNum.Text)
        dlgCom.Filename = strFilename
        strFilename = "A:\Data.dat"
        recordLength = Len(udtCredit)


    If intAccNum < 0 And intAccNum > 30 Then
        intUserResponse = MsgBox(conMsg, conBtns, "Unlimited Credit")
    End If
        If mskAccNum.Text = "" Then
            MsgBox "You must enter an Account Number before saving this Record.", conBtns, "Validation Error"
        Else

            Open "A:\Data.dat" For Random As #1 Len = recordLength
                udtCredit.intAccNum = Val(mskAccNum.Text)
                udtCredit.dteBirth = mskBirth.Text
                udtCredit.strLast = txtLast.Text
                udtCredit.strFirst = txtFirst.Text
                udtCredit.curBalance = Val(mskBalance.Text)
                udtCredit.strTelNum = mskTelNum.Text
                udtCredit.intIDNum = Val(txtIDNum.Text)
                lblDate1.Caption = Date
               
            For x = 1 To 30
                Put #1, udtCredit.intAccNum, udtCredit
            Next
        End If
 
   
    Close #1
    Call ClearFields
errHandler:

        mskAccNum.SelStart = 0
        mskAccNum.SelLength = Len(mskAccNum.Text)
        mskAccNum.SetFocus

End Sub

I have tried commenting out the For Loop and moving it but I cant seem to get it to write.
It will create a new file if I delete the old one but it still wont write to it.
Many thanks for any help.  
0
Comment
Question by:Ned_Kelly
  • 3
  • 2
  • 2
7 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 6195954
I have seen several issues:
you write Put #1, udtCredit.intAccNum, udtCredit
but defined the file to have recordlength of len(udtCredit)

You have
If mskAccNum.Text = "" Then
  ...
Else
  Open "A:\Data.dat" ...
  ...
End If
Close #1

And it must be  
If mskAccNum.Text = "" Then
  ...
Else
  Open "A:\Data.dat" ...
  ...
  Close #1
End If

Hope this helps

           
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6195967
But why are you writing 30 times to the same account number?

and:

If intAccNum < 0 And intAccNum > 30 Then

will never occur because a number can't be both < 0 and > 30 at the same time.

You do have your old code to compare it against, right?  Post it so we can compare.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6196044
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:Ned_Kelly
ID: 6197724
This cmdEnter is from the frmCredit whereas the other question link(angellll) is for the cmdEnter on the frmTrans.
The original code has been overwritten as I resave the floppy to the main drive, it will be a practice that I intend to take up, keeping a copy of the working code.   I cant see the reason why it isn't working though.
I have worked out why it wont write, I changed the AllowPrompt in the properties box for the MaskEditBoxes from true to false.  The reason I did this was so that when I type in an account number and press find it will bring up the acount details.  Before I did the change it would not return the values for the MaskEditBoxes, but it does when you change it to false.
I have a problem

Thanks for your comments and help for a beginner.
Ned
0
 

Author Comment

by:Ned_Kelly
ID: 6198130
Hi, the line

If intAccNum < 0 And intAccNum > 30 Then

is for checking to see if the number falls between 1 and 30 as that is the range of records for the application, as it is a school project only.
If it is out of this range then the msgbox comes into play.
I'm going to accept angellll's answer as I need to ask another question.
Ned
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6203234
"see if the number falls between 1 and 30"

The proper syntax should be
1) <= 0, OR:

If intAccNum <= 0 OR intAccNum > 30 Then
  ' out of range

2) >0, <=30:

If intAccNum > 0 And intAccNum <= 30 Then
   ' in range
else
   ' out of range
end if
0
 

Author Comment

by:Ned_Kelly
ID: 6203314
Yes you are right, I can only go by what we are taught until we can then start to think for ourselves.
My Vb instructor uses the sink or swim method, ie
you go in to class and he starts by taking you through the tutorial, at the same time you are frantically typing to keep up with him, then you are left to fixed any errors of which they are almost always there.
You then go home and start on the project for the week, come back the next week and do it all over again, meanwhile the projects are getting harder.
You do this for ten weeks and that was the end of the first module, of which I passed.
The next six week module was a browser and then the Credit app of which I now ask questions, we have to hand it in so that is works well with no errors or we fail.

It is worth 80% of the module, I fail tomorrow night, But I know I tried my best, so I can only go and practice some more and resit the module.
But I haven't give up yet.

Thanks for you rcomment RspahitZ,
I will adjust my code accordingly thankyou.
Ned
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

770 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