Recordset Condition

imfarhan

Board Regular
Joined
Jan 29, 2010
Messages
123
Office Version
  1. 2016
Platform
  1. Windows
Hi All,
I have a function when the value is Null its stopped which is great but when the value in the field(date) value. it working great.

The field which is checking its date value. But some time if the date value is old date meaning not equal to today's date(Now) it shouldn't be run but some how it run , I have use the following condtion please help

Code:
Private Function TestInfoCom() As ReturnStatus
    Dim rs As DAO.Recordset
   'Dim dtMEnd_dtime As Date
    Dim A As DAte
    Dim B As String
    
    On Error GoTo Err_Handler
    
    'Check INFoCOM for the daily reports
    Set rs = CurrentDb.OpenRecordset("qryTest_InfoCom_Completion", dbOpenDynaset)
    
    'rs.MoveFirst
    'A = Weekday(rs.Fields("maxofend_dtime").Value)  ' Add on 22-Aug-2011
    'B = Weekday(Now())                              ' Add on 22-Aug-2011
    
    If rs.RecordCount = 0     OR A <> B Then ' add "OR" condition because Automation start even the old date/value exist in field qryTest_InfoCom_Completion.maxofend_dtime
    
     MsgBox "InfoCom not Completed"
    'And Weekday(rs.Fields("maxofend_dtime").Value) <> Weekday(Now()) Then
    'And Format(rs.Fields("maxofend_dtime").Value, "DD/MM/YYYY") <> Format(Now(), "DD/MM/YYYY") Then
    'Or Weekday(rs.Fields("maxofend_dtime").Value) <> Weekday(Now()) Then 'Add the condition if the Day of the week not same as today's day its return nothing
            '03/12/09 add the new check if date is not equal to today's date
        'Not completed yet
        
        rs.Close
        Set rs = Nothing
        TestInfoCom = NothingToDo
        Exit Function
    End If

I have control by using A <> B when the old date exist in the field but when the rs is NUll its generate error.

I hope it does make sense.
Many thanks

Farhan
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
More info......

So when I keep both condition together … like <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
rs.RecordCount = 0 and A <> B …… and the rs. pulling Null (As its currently running….)<o:p></o:p>
<o:p></o:p>
<o:p>Meaning when RS is null its generate error(coz of varable "A") but when rs. got value both conditoin working fine...</o:p>
<o:p> </o:p>
How can I keep both condition when RS is Null.
<o:p> </o:p>
Many thanks<o:p></o:p>
 
Upvote 0
Why aren't you checking if the value us null?

That's the first thing you should do.

Then to find out if there are a problem with the conditions split things up instead of trying to do it all in one go.
 
Upvote 0
Thanks Norie,
I was checking the 2nd condtion in the same IF conditon , where it should be check using ELSE IF condtion as shown below:
I thnk its working fine...


Code:
   If rs.RecordCount = 0 Then
     MsgBox "InfoCom not Completed"
    'And Weekday(rs.Fields("maxofend_dtime").Value) <> Weekday(Now()) Then
    'And Format(rs.Fields("maxofend_dtime").Value, "DD/MM/YYYY") <> Format(Now(), "DD/MM/YYYY") Then
    'Or Weekday(rs.Fields("maxofend_dtime").Value) <> Weekday(Now()) Then 'Add the condition if the Day of the week not same as today's day its return nothing
            '03/12/09 add the new check if date is not equal to today's date
        'Not completed yet
 
        rs.Close
        Set rs = Nothing
        TestInfoCom = NothingToDo
        Exit Function
 
     Else
       'A = Weekday(rs.Fields("maxofend_dtime").Value)  ' Add on 22-Aug-2011
       A = Weekday(rs.Fields("empno").Value)  ' Add on 22-Aug-2011
       B = Weekday(Now())                              ' Add on 22-Aug-2011
 
     If A <> B Then ' add "OR" condition because Automation start even the old date/value exist in field qryTest_InfoCom_Completion.maxofend_dtime
 
        rs.Close
        Set rs = Nothing
        TestInfoCom = NothingToDo
        Exit Function
     End If
    End If
 
Upvote 0
You might still want to check for Null.

That should probably be the first thing to do.
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,099
Members
449,205
Latest member
ralemanygarcia

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