Help ! Please - 'Object Required'

PhilipEwen

Registered User.
Local time
Today, 03:04
Joined
Jun 11, 2001
Messages
81
Hi,
I am trying to error trap. When someone gets presented with data on a client, they can click a date on the record and it opens a detailed form presenting them with all the data relevant to the date they clicked.
The PROBLEM is that if there is no data ( past history of the client ) i want to make it so that if the user clicks on the blank datasheet output, it comes up with a messgae saying 'There is no past data on the client'.

Here is my code:
Private Sub TreatmentDate_DblClick(Cancel As Integer)


On Error GoTo Err_TreatmentDate_DblClick

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Customer_Treatment_Detailed"
stLinkCriteria = "[TreatmentID]=" & Me![TreatmentID]

If Me![TreatmentID] Is Null Then
Dim strTitle As String
Dim strMessage As String
Dim lResponse As Long
strTitle = "No Treatment History"
strMessage = "There is no history for this Customer, please Add a History"
lResponse = MsgBox(strMessage, vbInformation + vbOKOnly, strTitle)
Cancel = True
Me.Undo

Else

DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

Exit_TreatmentDate_DblClick_:
Exit Sub

Err_TreatmentDate_DblClick:
MsgBox Err.Description
Resume Exit_TreatmentDate_DblClick_


End Sub

This should therefore check to see if the TreatmentID has no content, then display a message and exit. If there is a TreatmentID on the form, then it goes off and opens the detailed form.

I just get 'not object type' message.

I am new to VB ( day 2 ) so a full explanation would be really appreciated. ( or a better way of doing it !! )

Many thanks
 
okay, what you could do is run a quick SQL statement to see if there is data for that record in the underlying table of the form...

dim MyDB as database
dim MyRecs as recordset
dim MySQL as string

set MyDB = currentdb
MySQL = "SELECT * FROM [Your_Table]WHERE "TreatmentID=" & Me![TreatmentID]
set MyRecs = MyDB.openrecordset(MySQL)

if myrecs.eof then
msgbox "There is no past data on the client."
resume Exit_TreatmentDate_DblClick_
end if
'Now the rest of the code you have to open the form.
 

Users who are viewing this thread

Back
Top Bottom