[AccessD] A2K: Stop User from oving to new record

Gustav Brock gustav at cactus.dk
Mon Apr 12 09:04:45 CDT 2004


Hi Darren

> Hi Bryan
> I did that no joy eg.

That is because your expression will never be True as

  Me.cmbOffence = ""

will be Null if Me.cmbOffence is Null, and then

  IsNull(Me.cmbOffence) Or Null

will return Null as well.

The fastest method is:

  If Len(Me.cmbOffence & vbNullString) = 0

but mostly I prefer to use Nz():

  If Len(Nz(Me.cmbOffence, vbNullString)) = 0

As Stuart mentions, you may omit the last part, but you must be sure
that the value tested is either Null or a string (which is the case
here as I guess cmbOffence is a combobox):

  If Len(Nz(Me.cmbOffence.Value)) = 0

/gustav


> Private Sub Form_BeforeUpdate(Cancel As Integer)

> If IsNull(Me.cmbOffence) Or Me.cmbOffence = "" Then
>     MsgBox "Enter an offence"
>     Cancel = True
> End If

> End Sub

> What I need to do is somehow test if the user is on a new fresh record or has left th previous record with unfilled combos. Of
> course I can do it on the lost and got focus event.Thats fine whilst I am in the record
> EG record 5 has no offence recorded
> User goes to record 6 How do i alert the user that record 5 has a missing value then go back to that record?


> ----- Original Message ----- 
> From: "Bryan Carbonnell" <carbonnb at sympatico.ca>
> To: "Access Developers discussion and problemsolving" <accessd at databaseadvisors.com>
> Sent: Monday, April 05, 2004 10:25 AM
> Subject: Re: [AccessD] A2K: Stop User from oving to new record


>> On 5 Apr 2004 at 10:08, Darren DICK wrote:
>>
>> >  I have a simple subform with 4 fields on it
>> > ID (PK),  txtDateOfOccurence, cboClientName, cboOffence
>> >
>> > How can I tell if the user goes to a new record and they have not
>> > completed ALL fields in the previous record How do I alert them and
>> > then direct them back to the previous record?
>>
>> Use the before update event of the form. Check to make sure they
>> entered a vale and if not set Cancel = true in the event. That should
>> prevent the record from being saved and keep the sub form on the
>> "unfinished" record




More information about the AccessD mailing list