MS Access ------ Macro If - Else statement Not Working

Santhosh23

New Member
Joined
Aug 3, 2015
Messages
11
Hi ..

I have a subform which stores 3 VALUES Start Time , End Time and Work Time..I am creating a macro to check for the worktime greaterthan 8 hrs and send email to particular person . This is the macro function I used..

If [Forms]![RecordSubform]![Label17]>=8 then
email database object

Else
Msgbox .."No user Logged in morethan 8 hrs"..

when i executed this query it always goes to else statement and I receive this message box ..while my subform has the below values..

StartTime End Time WorkTime
07/27/15 04:55:27 PM 07/27/15 04:56:39 PM 00:01:12
07/27/15 04:57:03 PM 07/27/15 04:58:10 PM 00:01:07
07/27/15 04:58:26 PM 07/27/15 04:59:55 PM 00:01:29
07/28/15 05:22:03 PM 07/29/15 07:01:13 AM 13:39:10
07/29/15 08:04:46 AM 07/29/15 08:04:50 AM 00:00:04
07/29/15 08:05:27 AM 07/29/15 08:05:33 AM 00:00:06
07/30/15 07:40:03 AM 07/30/15 07:40:09 AM 00:00:06
07/30/15 03:11:14 PM 07/30/15 03:11:18 PM 00:00:04
07/31/15 07:49:14 AM 07/31/15 04:19:55 PM 08:30:41
26:07:15 10:24:35 PM 26:07:15 10:24:39 PM 00:00:04

Can anyone please help on this..

Thanks in advance
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
You dont need an IF,
open query that has the criteria : [Forms]![Mainform]![RecordSubform]!forms![Label17]>=8
then email to everyone in the list.

(but you must give the full path to the sub form) yours didnt. use the builder to get the correct path.
 
Upvote 0
You dont need an IF,
open query that has the criteria : [Forms]![Mainform]![RecordSubform]!forms![Label17]>=8
then email to everyone in the list.

(but you must give the full path to the sub form) yours didnt. use the builder to get the correct path.

Hi ..ranman256 ..thanks for the help..did you mean to enter the query in the queryname.. and what properties should be specified for view and data mode..

I executed this query [Forms]![Navigation Form]![RecordSubform]!forms![Label17]>=8 and got an 7873 error..
 
Upvote 0
Sounds like your subform reference is wrong (maybe [RecordSubform] is not the name of your subform).
The syntax for referencing CONTROLS on subform:
[Forms]![Main form name]![subform control name].[Form]![control name on subform]

I have found that the syntax is different for referencing properties of a sub form:
forms("MainFormName").Controls("subformControlName").Form.Recordset.Recordcount

NOTE: subformcontrol name is NOT the name of your subform. It is the name of the subform control on the main form that contains the subform.

Is Label17 a label? If so, I think you will have issues with the way you are using it.
 
Upvote 0
use the BUILDER to get the path to the text box correct.
you cant loose using the builder.
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top