Senin, 24 Oktober 2011

Re: [MS_AccessPros] Unwanted Saving a blank record -- form BeforeUpdate

 

Crystal:
Thanks, The primary reason for this form is to allow the user to choose an existing record to populate controls on the calling form, so most of the time no new record would be generated. The odd behavior is that it seems to make a new record when the query to populate the form runs?? I have looked at the table in question right after opening the form (doing nothing else) and a blank record seems to have appeared?? I am not updating anything (that I know of..)

Would this stifle that behavior?

"Before_update_Event"
If IsNull(me.SomeControlName) then (Choose any control)
cancel = true
endif

Walter Griffin

--- In MS_Access_Professionals@yahoogroups.com, Crystal <strive4peace2008@...> wrote:
>
> Hi Walter,
>
> absolutely!  the purpose of the form BeforeUpdate event is to cancel a new record or a change to an existing record.  This is exactly what you want to do.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> 'to validate a record and prevent it from being saved, put code in the form BeforeUpdate event
>    '----------------- make sure all required data is filled out
>
>    'make sure SomeControlName is filled out
>    If IsNull(me.SomeControlName) then
>  
>       'if it is not filled out,
>       'then move the focus to that control
>       me.SomeControlName.setFocus
>  
>       'give the user a message
>       msgbox "You must enter Some Data",,"Missing Data"
>  
>       'if this is a combobox, drop the list for them
>       me.SomeControlName.dropDown
>
>       'IF you want to undo the record
>       'Me.Undo 
>
>
>       'don't save the record yet
>       Cancel = true
>  
>       'quit checking and give them a chance to fill it out
>       exit sub
>    end if
>  
>    'make sure the first Date is filled out
>    If IsNull(me.Date1) then
>       me.Date1.setFocus
>       msgbox "You must enter the first Date" _
>           ,,"Missing Data"
>       Cancel = true
>       exit sub
>    end if
>  
>    'make sure the second Date is filled out
>    If IsNull(me.Date2) then
>       me.Date2.setFocus
>       msgbox "You must enter the second date" _
>           ,,"Missing Data"
>       Cancel = true
>       exit sub
>    end if
>  
>    'make sure the second Date2 is after Date1
>    If me.Date2 < me.Date1 then
>       me.Date2.setFocus
>  
>       msgbox "The second date, " & me.Date2  _
>           & " must be after the first date, " _
>           & me.Date1,,"Invalid Data"
>       Cancel = true
>  
>       'IF you want to undo the entries to the record
>       'Me.Undo
>  
>       'IF you want to undo the entries to the field
>       'Me.controlname.Undo
>       Cancel = true
>       exit sub
>    end if
>
> '~~~~~~~~~~~~~~~~~~~~
>
> WHERE
> controlname is the Name of the respective control
>
> substitute your controls names for these:
> SomeControlName
> Date1
> Date2
>
>
> Warm Regards,
> Crystal
>
> Learn Access on YouTube
> http://www.youtube.com/user/LearnAccessByCrystal
>
>  *
>    (: have an awesome day :)
>  *
>
>
>
> ________________________________
> From: nkpberk
>
> Hi Group;
>
> I have a annoying problem, one of my forms, when opened and the query runs that populates it, saves a blank record in the root table the query is based on!
>
> This form is called from more than one control/form and the criteria is passed thru 'openargs' valued to invisible textboxes to give the appropriate records to the form.
>
> How do I prevent this from happening? I suppose I could do a "delete" query on the root table on form close, but I would like to know if there is a way to prevent it.
>
> I do want the user to be able to add a record with data if they want or just choose an existing record to populate other controls on the calling form. I think I can manage that part.(I think :-)
>
> Walter Griffin
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
> [Non-text portions of this message have been removed]
>

__._,_.___
Recent Activity:
MARKETPLACE

Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.

.

__,_._,___

Tidak ada komentar:

Posting Komentar