please critique my code! (1 Viewer)

gino

Registered User.
Local time
Today, 11:50
Joined
Mar 16, 2000
Messages
117
Here is a code i've just created and it works well, but i was wondering if it is possible for this message to show up only once? this is just a reminder message and i wish for this message to appear only once. I want the message "How many corrective actions have you created?" to appear only once but message "Record has been saved!" to appear always based on if statement. check my code out.

Private Sub save_record_GotFocus()
If Me![TOTAL CORRECTIVE ACTIONS] >= 1 And Me![NUMBER OF CORRECTIVE ACTIONS] = 0 Then
MsgBox "How many corrective actions have you completed?", vbOKOnly
Me![NUMBER OF CORRECTIVE ACTIONS].SetFocus
Else
If Me![DATE].Value Then MsgBox "Record has been saved!"
End If

End Sub

Thanks to everyone in advance!
 

Kensan

New member
Local time
Today, 11:50
Joined
Apr 21, 2000
Messages
9
Depending on how you are using the form, thjis code might work. I've added a few lines to your original code.

Private Sub save_record_GotFocus()
Static flag As Integer

flag = 0

If Me![TOTAL CORRECTIVE ACTIONS] >= 1 And Me![NUMBER OF CORRECTIVE ACTIONS] = 0 Then
if flag = 0 then
MsgBox "How many corrective actions have you completed?", vbOKOnly
flag = 1
end if
Me![NUMBER OF CORRECTIVE ACTIONS].SetFocus
Else
If Me![DATE].Value Then MsgBox "Record has been saved!"
End If

End Sub

Declaring flag as static means that it retains its values between procedure calls. The variable is initialised only once ( = 0 ), during the first call.
flag will retain its values while the envireonment in which it is runs is still running. This means that it will not be reset back to zero until you quit Access then fire it up again and run the code that calls the procedure.

If this doesn't solve the problem, one avenue of investigation might be to store a value in a controls tag property (this would be a string but you could set it to "0" as the default then the first time the message box is displayed set it to "1"). Each time you want to display the message box check the value in the tag property.

Hope this helps
 

Users who are viewing this thread

Top Bottom