Results 1 to 4 of 4

Thread: DB Problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    20
    I have an access97 db attached to my vb 5 program with DAO. When I type a record in it will save the record to the database no matter what. So if the user doesnt complete fields the record is still saved to the database. Does anyone know how to not save the record to the database say if a certain field wasnt filled out?
    So it would abandon the record if certain fields were not completed??
    Thanks

  2. #2
    Member
    Join Date
    Sep 2000
    Posts
    34
    There are a few ways you could do it. You can do it on the form, and just have the "submit" button or whatever you are using check feild and if any are blank, exit before a record is added. This is not as stupid-proof as setting it up in the database however.

    Open you database up in deign mode. select the field you want to have required and look at the bottom of your window. There should be options for 'Required'

    Set that to Yes and the database will throw an error instead of saving the record.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    20
    Is there a way I can trap that error in vb then?

  4. #4
    Member
    Join Date
    Sep 2000
    Posts
    34
    Yes... But I forget how. If you throw error handling in your subroutine, it may trap it there... for example:

    Sub DO_WHATEVER_WHEN_I_CLICK_MY_BUTTON_Click()
    On Error GoTo Err_DO_WHATEVER_WHEN_I_CLICK_MY_BUTTON_Click


    Exit_DO_WHATEVER_WHEN_I_CLICK_MY_BUTTON_Click:
    Exit Sub

    Err_DO_WHATEVER_WHEN_I_CLICK_MY_BUTTON_Click:

    'The MsgBox line is the error line.
    'You might try replacing it with something like:
    'msgbox "You left one or more required fields blank"

    MsgBox Err.Description

    Resume Exit_DO_WHATEVER_WHEN_I_CLICK_MY_BUTTON_Click

    End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width