Jeff said:
Thank you for your help. I have tested the method you told me and it works.
I can’t get it work in a “data formâ€, because the background color cannot
cross through the whole section. A data form is like a form when we click and
open an Access table. I am not sure if I tell the right term because my
Access is not an English version.
My first problem is I cannot set focus to the record found after searching.
I know there is something to do with “Bookmarkâ€, but I can't figure it out. I
have a main form displaying clients'ID, name, phone number….., a subform on
the main form is for recording the appointments with any clients, i.e. the
subform is independent and not related to the main form.
In the CmdButton's Click event(the button is on main form):
Set rstObject = dbObject.OpenRecordset(strQuery)
With rstObject
.FindFirst "[MasterID]=" & Me![ID]
If .NoMatch Then
.AddNew
![MasterID] = Me![ID]
!Phone = Me![Phone]
!Date = Me![Date]
.Update
.Close
Else
MsgBox “This client already has an appointment with usâ€
…….let focus go back to the record found on the subform
End If
End With
Me![subform].Form.Requery
dbObject.Close
Set dbObject = Nothing
When the user finds a client already has an appointment, I'd like that
record be set focus. Any further help is appreciated.
I gather you're using the form in DataSheet view, where I
was assuming you were in Continuous view. I highly
recommend a continuous form because of its many capabilities
that don't exist in sheet view. However, if you prefer
sheet view you can set up the header text box and the
current event as I described before. Then, instead of the
one big text box, use CF on each or the text boxes in the
detail section.
I think you can add the new record in the subform and
position it using something more like:
With Me.[subformcontrol].Form.RecordsetClone
.FindFirst "[MasterID]=" & Me![ID]
If .NoMatch Then
.AddNew
![MasterID] = Me![ID]
!Phone = Me![Phone]
!Date = Me![Date]
.Update
Me.[subformcontrol].Form.Bookmark = .LastModified
Else
MsgBox “This client already has an appointment with
usâ€
Me.[subformcontrol].Form.Bookmark = .Bookmark
End If
End With