By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,462 Members | 2,360 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,462 IT Pros & Developers. It's quick & easy.

Comparing dates in a recordset

tuxalot
100+
P: 200
I am running this code in a hidden validation form and trying to compare dates (registered, date db was last accessed and the system date of the PC). I can't seem to get the check tampering code working. I've been staring at this for far too long and I guess I'm overlooking something. Any help is appreciated.

Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT * FROM tblColors WHERE [SerialHDD] = '" & strHDD & " '"
  2. Set db = CurrentDb
  3. Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
  4.  
  5. If rs.EOF = True Then
  6.     MsgBox "It appears that you are not registered. Opening registration form."
  7.     DoCmd.OpenForm "frmRegister", acNormal, , , acFormEdit, acWindowNormal
  8.     DoCmd.Close acForm, "frmValidate"
  9.     Exit Sub        'once user has completed registration, open this form again
  10. Else
  11.     'check tampering - did the user roll back his PC clock
  12.     If CLng(Date) < CLng(rs!DateLastAccessed) Then
  13.         MsgBox "It appears that the database has been tampered with. Please contact support."
  14.         Call dbTamper
  15.         DoCmd.Close
  16.     End If
  17.  
  18.     'check tampering - did the user roll back date accessed in local table
  19.     If CLng(rs!DateRegistered) > CLng(rs!DateLastAccessed) Then
  20.         MsgBox "It appears that the database has been tampered with. Please contact support."
  21.         Call dbTamper
  22.         DoCmd.Close
  23.     End If
  24. End If
Dec 16 '11 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 446
Hi
I don't fully understand what is happening here, so humour me!

You are setting up a recordset and then assuming that if it's EOF there are no records. Fair enough but I usually check if RecordCount =0. You then open two forms, so the focus is going to move from the current form to one of these new forms. Depending upon whether they are 'pop-up' or 'modal', goodness knows where the focus and next line of code will be.

Else, if the recordset is not empty, you are assuming there is only one record.. OK.. You are then trying to read 'rs!DateLastAccessed' without a WITH statement. I think this is why the check is going wrong.

S7
Dec 16 '11 #2

TheSmileyCoder
Expert Mod 100+
P: 2,321
You REALLY need to tell us what you mean by "Not working". Not working can mean a lot of things. It could be throwing an error. It could be that it evaluates everything to true, or everything to false. It could be that it fails under specific circumstances.

Try setting a break point at the lines where you make the date comparison, hower the mouse over the recordsets and see what value the date has.
Dec 16 '11 #3

NeoPa
Expert Mod 15k+
P: 31,186
Tux, you should be past these nooby errors by now. Smiley is absolutely right, but you don't show the declarations of your variables either. See When Posting (VBA or SQL) Code. You've copied it directly, which is good, but I'm going to strip out the spare indentation (evenly) for you, to make it more easily viewed on here.

Declarations are particularly important when dealing with recordsets as they come in both DAO and ADODB flavours, and they are not the same.

Line #1 includes an extra space after strHDD and before the SQL string quote (in other words would look like WHERE [SerialHDD] = 'nnnnn '). This is probably a mistake.

I may disagree somewhat with S7 on checking for empty recordsets. Checking EOF is more reliable as RecordCount is not set immediately in all situations (for instance when the data set is large and/or it is not Jet provided).

The date checking is unnecessarily awkward from my PoV, but I see nothing there which shouldn't work, assuming all the date fields contain valid data. At this point it might be a good idea to remind you that you haven't included that fundamental information in your question either.
Dec 16 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.