Connecting Tech Pros Worldwide Help | Site Map

When shall i call my function?

simonmarkjones@gmail.com
Guest
 
Posts: n/a
#1: Nov 13 '05
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

Keith
Guest
 
Posts: n/a
#2: Nov 13 '05

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


Salad
Guest
 
Posts: n/a
#3: Nov 13 '05

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 Microsoft Access / VBA bytes