Force the user to do something before the form updates!?

G

Guest

I have a very complex form with many different users changing and updating
the records in a network. My ambition is to logg the employee who made the
latest change to the record and to set the date of when the last change
occured.

With the below code it is still possible for the user to ignore my logging
ambititions
and leave the form without entering his name in the listbox for employee.
The date is set anyway.

What I want to do is to lock to the form on the current record until the
listbox for emloyee has been changed

I have this code below running on the forms before update event.

Thank you in advance

Mattias
Private Sub Form_BeforeUpdate(Cancel As Integer)

Forms!OBJEKTREGISTRERING!DateLatestChange = Date
cboEmployee2.BackColor = vbYellow
Employee1Name.BackColor = vbYellow
DoCmd.GoToPage (3)
DoCmd.GoToControl "cboEmployee2"
End Sub
 
M

Marshall Barton

Mattias said:
I have a very complex form with many different users changing and updating
the records in a network. My ambition is to logg the employee who made the
latest change to the record and to set the date of when the last change
occured.

With the below code it is still possible for the user to ignore my logging
ambititions
and leave the form without entering his name in the listbox for employee.
The date is set anyway.

What I want to do is to lock to the form on the current record until the
listbox for emloyee has been changed

Private Sub Form_BeforeUpdate(Cancel As Integer)

Forms!OBJEKTREGISTRERING!DateLatestChange = Date
cboEmployee2.BackColor = vbYellow
Employee1Name.BackColor = vbYellow
DoCmd.GoToPage (3)
DoCmd.GoToControl "cboEmployee2"
End Sub


I think all you need is to check the list(?) box to see if
it's Null and refuse to let the update procede:

If IsNull(listbox) Then
MsgBox "you must identify yourself"
Cancel = True
Else
'your existing code
End if
 
G

Guest

Hi

Sorry for late reply. It seem to be a good idea..checking for null or
onother value is enough. If onother employee did change the record yesterday!?

The best solution would have been if I could check if the cboEmployee2
have been changed during this change

Mattias
 
G

Guest

Hi

Sorry for the late reply.

Is there any easy way to match the logon string name connect to my unique
number field for the emplyee. Can you please give me an code example of this.

Mattias
 
M

Marshall Barton

Will this do what you want?

If IsNull(listbox) Or (listbox = listbox.Oldvalue) Then

BTW, if Dale's idea pans out, all this becomes moot.
 
G

Guest

Hi

Much better now, seems safe!..looks like below, but it never goes down goes
further when clicking msgbox

Thanks

Mattias

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(cboAnställd2) Or (cboAnställd2 = cboAnställd2.OldValue) Then
MsgBox "Du måste identifiera dig"
Cancel = True
Else
Forms!OBJEKTREGISTRERING!SenasteÄndringdatum = Date
cboAnställd2.BackColor = vbYellow
ANSTÄLLDA1Förnamn.BackColor = vbYellow
DoCmd.GoToPage (3)
DoCmd.GoToControl "cboAnställd2"
End If

End Sub

Marshall Barton said:
Will this do what you want?

If IsNull(listbox) Or (listbox = listbox.Oldvalue) Then

BTW, if Dale's idea pans out, all this becomes moot.
--
Marsh
MVP [MS Access]


Sorry for late reply. It seem to be a good idea..checking for null or
onother value is enough. If onother employee did change the record yesterday!?

The best solution would have been if I could check if the cboEmployee2
have been changed during this change
 
M

Marshall Barton

I'm sorry, but I don't understand. Is it doing what you
want, or is there another question?
 
G

Guest

Sorry,

The code stops running after I have clicked the buttun on the msgbox.
I would like go further below the Else line

Mattias

Marshall Barton said:
I'm sorry, but I don't understand. Is it doing what you
want, or is there another question?
--
Marsh
MVP [MS Access]


Much better now, seems safe!..looks like below, but it never goes down goes
further when clicking msgbox

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(cboAnställd2) Or (cboAnställd2 = cboAnställd2.OldValue) Then
MsgBox "Du måste identifiera dig"
Cancel = True
Else
Forms!OBJEKTREGISTRERING!SenasteÄndringdatum = Date
cboAnställd2.BackColor = vbYellow
ANSTÄLLDA1Förnamn.BackColor = vbYellow
DoCmd.GoToPage (3)
DoCmd.GoToControl "cboAnställd2"
End If

End Sub
 
M

Marshall Barton

That violates the concept of If ... Then - Else.

In general, you should add whatever code you want in the
Then clause, even if it's similar to some of the code in the
Else clause. If some of the code in both clauses is
identical, then move it below the End If.

If that doesn't make sense, post back with a more detailed
description of what you want to happen in the Then and Else
clause's and what should happen regardless.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top