Selasa, 01 November 2011

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

 

Walter-

There has to be some code that is "dirtying" the record and then forcing a save
to cause BeforeUpdate to fire. What is all the code behind the subform and the
parent form?

John Viescas, author
Microsoft Office Access 2010 Inside Out
Microsoft Office Access 2007 Inside Out
Building Microsoft Access Applications
Microsoft Office Access 2003 Inside Out
SQL Queries for Mere Mortals
http://www.viescas.com/
(Paris, France)

-----Original Message-----
From: MS_Access_Professionals@yahoogroups.com
[mailto:MS_Access_Professionals@yahoogroups.com] On Behalf Of nkpberk
Sent: Tuesday, November 01, 2011 7:54 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] Unwanted Saving a blank record -- form BeforeUpdate

Crystal,Group;
I am still having difficulty with a continuous form that creates a blank record
in a table. This time it won't allow the form to populate with the records
called for in the query. The before update event fires before the load event and
I get no existing records. also I get a warning messagebox about "encountering
some difficulty and can't save record at this time" I don't want this warning as
the primary use of the form is to allow the user a list of valid choices and
secondarily the ability to add a new record(choice).
using::
"Before_update_Event"
If IsNull(me.SomeControlName) then (Choose any control)
cancel = true
endif
this does stifle the blank record creation but seems to block the loading of the
valid choice list (records)

Walter Griffin

--- In MS_Access_Professionals@yahoogroups.com, "nkpberk" <wgriffin48@...>
wrote:
>
> 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]
> >
>

------------------------------------

Yahoo! Groups Links

__._,_.___
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