Click to See Complete Forum and Search --> : DB Problem
ad1044
Sep 18th, 2000, 10:57 AM
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
damarious
Sep 18th, 2000, 11:29 AM
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.
ad1044
Sep 18th, 2000, 11:32 AM
Is there a way I can trap that error in vb then?
damarious
Sep 18th, 2000, 11:42 AM
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.