AfterUpdate

F

FPS, Romney

I have a form based on a query. The underlying table has a Yes/No field:
[SavedOnServer], with the default property set to No (0). This field is on
the form with visible = No.

What I would like is for the default value of this field to be changed from
No to Yes if the record has been changed and the user is on the network
drive "P". If the user is not on the network, that is they are on drive
"C", then I would like the field either to remain as No (in the case of a
new record), or to be changed to No if it was previously marked as Yes. I
have a function which retrieves the drive-letter of the path -- "P" for
network and "C" for home use.

I've nested some If-Then statements and although the following code works as
planned to update this field, I've noticed that after changing the record
and then clicking on a Close button, or clicking on the Record Selector bar
that nothing happens for the first click. For example, the record-edit
symbol (the pencil) on the Record Selector bar doesn't change. Clicking a
second time, however, saves the record and, in the case of the Close button,
saves the record and closes the form.

Could someone please advise me as to how to change this code?
Thank you,
Mark

Private Sub Form_AfterUpdate()
If Left(GetLinkedDBName("Names"), 1) = "P" Then
'If you're on the server, and it's a new record (default="No")
' then set the flag to "Yes"
If Me!SavedOnServer = 0 Then
Me!SavedOnServer = -1
End If
ElseIf Left(GetLinkedDBName("Names"), 1) = "C" Then
'If your're not on the server, AND the flag is set to "Yes"
' then set the flag to "No"
If Me!SavedOnServer = -1 Then
Me!SavedOnServer = 0
End If
Else
Exit Sub
End If
End Sub
 
F

FPS, Romney

Figured it out ... it needed to occur with the BeforeUpdate event.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Select Case Left(GetLinkedDBName("Names"), 1)
Case Is = "P"
If Me!SavedOnServer.Value = 0 Then
Me!SavedOnServer.Value = -1
End If
Case Is = "C"
If Me!SavedOnServer.Value = -1 Then
Me!SavedOnServer.Value = 0
End If
End Select

End Sub
 

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