Connecting Tech Pros Worldwide Help | Site Map

When shall i call my function?

  #1  
Old November 13th, 2005, 11:04 AM
simonmarkjones@gmail.com
Guest
 
Posts: n/a
Hi im a newbie to Access only started programing VBA in Access today.

I've got a function that increments a number. I want to call this ONLY
when the complete record has been filled out.

Using the navigation buttons access creates a new record when the form
is filled out. So i want to call the function when it does this.

Cheers

  #2  
Old November 13th, 2005, 11:04 AM
Keith
Guest
 
Posts: n/a

re: When shall i call my function?


<simonmarkjones@gmail.com> wrote in message
news:1116428752.584741.264280@g14g2000cwa.googlegr oups.com...[color=blue]
> Hi im a newbie to Access only started programing VBA in Access today.
>
> I've got a function that increments a number. I want to call this ONLY
> when the complete record has been filled out.
>
> Using the navigation buttons access creates a new record when the form
> is filled out. So i want to call the function when it does this.
>[/color]
It depends what you're doing with the incremented number but for starters,
have you tried the form's After Update event?

Regards,
Keith.
www.keithwilby.com


  #3  
Old November 13th, 2005, 11:04 AM
Salad
Guest
 
Posts: n/a

re: When shall i call my function?


Keith wrote:[color=blue]
> <simonmarkjones@gmail.com> wrote in message
> news:1116428752.584741.264280@g14g2000cwa.googlegr oups.com...
>[color=green]
>>Hi im a newbie to Access only started programing VBA in Access today.
>>
>>I've got a function that increments a number. I want to call this ONLY
>>when the complete record has been filled out.
>>
>>Using the navigation buttons access creates a new record when the form
>>is filled out. So i want to call the function when it does this.
>>[/color]
>
> It depends what you're doing with the incremented number but for starters,
> have you tried the form's After Update event?
>
> Regards,
> Keith.
> www.keithwilby.com
>
>[/color]
The form's afterupdate event will work.

If the person is wanting to increment the number when the record is
complete, then it may be better to do it in the BeforeUpdate event. The
reason I mention this is that the person, if using a bound form to the
table, can check the NewRecord property since the increment may be
desired to only be increment at the time the record is created. The
person can check the validity in the BeforeUpdate event and if all the
fields pass muster keep cancel to False (the default) and then check the
NewRecord property.

To the original poster, Ex:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Nz(Me.Subject, "") = "" Then
'stop processing and don't save
MsgBox "Please enter a subject.", vbOKOnly, "Missing Data"
Me.Subject.SetFocus
Cancel = True
ElseIf Me.NewRecord Then
Me.IncrementField = 1 + 1 'or 2.
End If
End Sub
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
call of variadic function CryptiqueGuy answers 9 June 19th, 2007 09:15 PM
Anything wrong with this function? Anonymous answers 83 February 15th, 2007 04:55 PM
printing the address of a function Robert Seacord answers 57 October 2nd, 2006 05:55 PM
call js after page loads uNConVeNtiOnAL answers 4 July 20th, 2005 11:39 AM