Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Records in Form 1

Status
Not open for further replies.

mot98

MIS
Jan 25, 2002
647
CA
Hi All,

I have a form that shows the records from a table. The tables records are updated every few minutes.

In my form I compare two of the time fields and send an e-mail if the difference is over 10 minutes. This part is working great.

However, if for some reason my table has no records in it, I run into trouble. My code compares two fields from the table, but if the table is empty of course I get an error saying "The expression you entered has no value".

Here is my code to compare:
Code:
TimeDiff = DateDiff("n", Me.HLSTME, Me.CTime)

If TimeDiff > 10 Then
Call Send_Mail
Else
Call Form_Timer
End If

So I want the form to ignore this code if there are no records in the table.....how would I do this.

I have tried Me.Recordset.Recordcount but it doesn't seem to work.



mot98
[cheers]
"Is it friday yet?"
 
Judging by your code, you are comparing values from two text box controls on a form, right? If so, you could check for null values in those text boxes (wrap an IsNull function around each of them).

Code:
If IsNull(Me.HLHLSTME) Or IsNull(Me.CTime) Then
   'Do Nothing
Else
   TimeDiff = DateDiff("n", Me.HLSTME, Me.CTime)

   If TimeDiff > 10 Then
      Call Send_Mail
   Else
      Call Form_Timer
   End If
End If

If you actually want to lookup the values in the table to see if they exist, have a look at the DLookup function.
 
Not sure how your table would ever be empty, but whatever.

here is a possible way...
1. Put both TimeStamp fields on the form.
2. On the timer event (or whatever you are using) put code to see if either object is null
3. Re-work your code so if the if tests true, then the e-mail/query/code that is generating the error does not execute.

HTH

C-D2
 
Hi rjoubert,

That seemed to work great....

One last issue on this form, I have a form timer, and need to run a "Update Query" query to update the table that my data comes from.

How do I run the "Update Query" without the user having to respond to the prompts that you get when you run it manually.



mot98
[cheers]
"Is it friday yet?"
 
Have a look at the DoCmd.SetWarnings method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top