Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    Dec 2003
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    blank records in the form (Access 2000)

    In my form customers i want to forbid the user to leave the record if he has not written the CompanyName.To do this, i have put in the unolad
    event the following

    Private Sub Form_Unload(Cancel As Integer)
    If IsNull(Me.TypeID) Then
    MsgBox "please enter company !!! "
    DoCmd.CancelEvent
    End If
    End Sub

    I also have a button called back with which i return to the main form.
    I also have another button called AddIt, with which the new client is entered.
    My problem is, that when we open the form with the button AddIt,we can
    leave the from with the button Back even no company name is being entered.
    In this way i allow the user to leave the form with a blank company name
    and in fact my code in the OnOnload event is useless.
    May i ask for help ?



    Private Sub CmdBack_Click()
    If IsNull(Me.TypeID) Then
    MsgBox "please enter company !!! "
    DoCmd.CancelEvent
    Else
    DoCmd.OpenForm "FOrderInformation"
    End If

    Private Sub AddIt_Click()
    DoCmd.GoToRecord , "", acNewRec
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: blank records in the form (Access 2000)

    You want to prevent the users from leaving CompanyName blank, but your code tests if TypeID is null <img src=/S/confused.gif border=0 alt=confused width=15 height=20>.

    Why don't you set the Required property of the CompanyName in the table to Yes? Then Access will take care of most of the work for you.

  3. #3
    Lounger
    Join Date
    Dec 2003
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: blank records in the form (Access 2000)

    sorry please read companyname instead of typeid.

    I have made the required property to Yes,and if there is no company name no record is made, but Access
    contnues counting the numbers behind the screen. The solution to me is to disallow the possibility
    to use the back button. ? If the user cannot use this button, then he will be be forced to enter the CompanyName.It is interesting to
    know why it happens only with the button for a new record

    Best regards

  4. #4
    3 Star Lounger
    Join Date
    Oct 2001
    Location
    Newport, Gwent, Wales
    Posts
    257
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: blank records in the form (Access 2000)

    Why not use the on lost focus event? When the form opens set the focus immediately to the company name, then when the user clicks the button the code will check the control and carry out the relevant action. Clicking any button will cause the company name control to lose focus.

    ian

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: blank records in the form (Access 2000)

    <hr>Access contnues counting the numbers behind the screen<hr>
    Are you talking about autonumbers? Once you've started a new record with an autonumber key, that number is assigned and is no longer available even if you cancel creation of the new record. I hope you aren't counting on autonumbers being sequential, because that is a mistake.
    <hr>It is interesting to know why it happens only with the button for a new record<hr>
    Why what happens? Are we still talking about autonumbers? If you move back from an unsaved new record, the record will be saved automatically if the required fields are filled in. Even if the record is discarded, the autonumber is no longer available and the next higher number will be assigned when you create another new record.
    Charlotte

  6. #6
    3 Star Lounger
    Join Date
    Jul 2001
    Posts
    280
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: blank records in the form (Access 2000)

    Thank you for your reply

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •