Stopping DB after "free trial" etc (1 Viewer)

Mike375

Registered User.
Local time
Today, 16:16
Joined
Aug 28, 2008
Messages
2,548
I want to limit the number of times used on a "free trial" basis. I have picked "number of times" for two reasons. One being changing date on computer and "number of times" will tell me how active the person is with what I made. Although I could probably change what is below to be date based since the you can type in a date to the OnClick event. I could probably base something on the date entered plus 14 or whatever.

Firstly, does anyone see any potential problem with opening the form in design and changing the number entered on the OnClick event. It works fine but I don't know if there would be any corruption problems. The following was the only way I could think of to record but without having a value in a table.

The following code is on a label on another form.

DoCmd.SetWarnings False
DoCmd.OpenForm "Form1", acDesign, "", "", , acNormal
Forms!Form1!abc.OnClick = Forms!Form1!abc.OnClick + 1
DoCmd.Close acForm, "Form1"
DoCmd.OpenForm "Form1", acNormal, "", "", , acNormal
DoCmd.SetWarnings True


=Forms!Form1!abc.OnClick in an unbound textbox will give the value entered in the OnClick so it will be easy to use that to block any code.

If this appears to be a trouble free way does anyone know how I could do something similar in Excel to stop code from running.
 

Mike375

Registered User.
Local time
Today, 16:16
Joined
Aug 28, 2008
Messages
2,548
I managed to hande date OK to get around computer turn back but I can't get code to work. The following does nothing. A macro is fine but I can't hide a macro with MDE

DoCmd.SetWarnings False
DoCmd.OpenForm "Form1", acDesign, "", "", , acNormal
If Forms!Form1!xyz.OnClick <= Date * 86400 Then

Forms!Form1!xyz.OnClick = Date * 86400

End If
DoCmd.Close acForm, "Form1"
DoCmd.OpenForm "Form1", acNormal, "", "", , acNormal
DoCmd.SetWarnings True

In the macro the condition column is

[Forms]![Form1]![xyz].[OnClick]<=(Date())*86400 and the SetValue action is

Item [Forms]![Form1]![xyz].[OnClick]
Expression (Date())*86400

I am using *number because a date entered on the Event line is not read as a date and thus 1/1/08 is earlier than 30/12/08 but all OK with number.

Is there someway I can get the VBA to do what the macro is doing so I can hide it with MDE
 
Last edited:

Mike375

Registered User.
Local time
Today, 16:16
Joined
Aug 28, 2008
Messages
2,548
The code is not reading the IF.

Without the IF this part works

Forms!Form1!xyz.OnClick = Date * 86400

Is there some other way I can do the IF
 

NigelShaw

Registered User.
Local time
Today, 07:16
Joined
Jan 11, 2008
Messages
1,573
hi and merry Christmas!

Your IF might not be currently working as you have set it to

If x <= y then do something

What if was less than? The code would then stop as you only ask for greater than or equal to.

Regs

Nigel
 

Mike375

Registered User.
Local time
Today, 16:16
Joined
Aug 28, 2008
Messages
2,548
hi and merry Christmas!

Your IF might not be currently working as you have set it to

If x <= y then do something

What if was less than? The code would then stop as you only ask for greater than or equal to.

Regs

Nigel

Nigel,

But I want it to run if the entry on the line for OnClick is less than or equal to current date.

The macro condition is the same and working

[Forms]![Form1]![xyz].[OnClick]<=(Date())*86400

I am wondering if VBA If Then End If can't read what is written on an Event line?
 

Mike375

Registered User.
Local time
Today, 16:16
Joined
Aug 28, 2008
Messages
2,548
I found a solution, messy, but does the job.

First I had the value entered on the OnClick line tranfer to a text box on the form where the code is run. On the form where the code is run another text box based on =Date()*86400. That did not work but a macro worked using the same basis. It appears when the code is run the calculation for =Date()*86400 is lost, even though the form is not closed/opened or least the IF can't read it.

So I made a table with two fields and the value from the OnClick line entry is transferred to one field and the value of the other field is setvalued to Date()*86400.

The code then worked when the table values were used.

I will just add to the code a couple of lines at the end to bring the field values in the table back to null. If someone sees the table it won't matter. If they delete then nothing will work etc.
 

NigelShaw

Registered User.
Local time
Today, 07:16
Joined
Jan 11, 2008
Messages
1,573
hi again,

Your solution is a bit messy. What if a user went poking around the tables and found the fields? They could be altered.

My preferred method would be to declare the dates in vb and use them-

Code:
Dim DateOne As Date
Dim DateTwo As Date
Dim DateCalc As Integer

DateOne = 'your first date
DateTwo = 'your end date
DateCalc = DateTwo * 86400

If DateCalc <= DateTwo then
'your code here

Else

'your other code here

End If



Or try a between dates rather than a <=

I have always found setting variables better than not.


Hope that helps mate

Nigel
 

NigelShaw

Registered User.
Local time
Today, 07:16
Joined
Jan 11, 2008
Messages
1,573
can you post a sample?

Pm me if not and I'll send my email. The resulting code will be placed here for the benefit of others and a sample solution will be sent back.

Nigel
 

Mike375

Registered User.
Local time
Today, 16:16
Joined
Aug 28, 2008
Messages
2,548
Nigel,

Thanks for your interest. I posted a sample DB of my final results. I have also attached the same DB to this thread.

http://www.access-programmers.co.uk/forums/showthread.php?t=162942


Actually, I am getting lost. There is a thread I started on General with the DB attached, the DB I thik will do the job. It is there for all to use, with their own modifcations.

Now that I have it working ( I am self employed and the stuff has to work tomorrow:) actually by Monday January 5) I can look at the code you posted.

Although it works I am not happy with having to have the table. But that was the only way I could get the VBA to work. So far, I am caught between a rock and a hard place. A macro does not need the "hand holding" but I can't hide a macro with MDE. I can hide the code and it does not matter what someone does with the table.

It's 1.40am in Sydney Australia, so I will look at your code a bit later. If I look now I will get 10 from 4+3:D

As a side note, I have seen before where IF THEN END IF won't read the condition but a macro condition will read it, as is the case in my situation. Microsoft Australia just say.....horses for courses....what a useless reply

Will look at your code a few hours from now......
 

Attachments

  • FreeTrialTestingDateBasedForum.zip
    37.8 KB · Views: 206

NigelShaw

Registered User.
Local time
Today, 07:16
Joined
Jan 11, 2008
Messages
1,573
I can hide the code and it does not matter what someone does with the table.

Hi,

it matters what happens to the table if the dates entered are altered. then your process would fail.


Nigel
 

Mike375

Registered User.
Local time
Today, 16:16
Joined
Aug 28, 2008
Messages
2,548
Hi,

it matters what happens to the table if the dates entered are altered. then your process would fail.


Nigel

Not so, because the code does a setvalue. You can enter what you like in the table and it won't matter.

The table is only there so the VBA can work using the table/field as the reference. At the end it sticks a 0 in each of the two fields and that is just for appearance. If someone decides to paste in a 1000 records that makes no difference.

The only values that count are those on the OnClick line and with MDE I can't see how anyone can get to those.

At the moment the only way I can see around the "block" is if the person using a program (where this must be run) always changes the computer date BEFORE they run it.

But you enter whatever in the table......The table/fields are only replacing unbound text boxes because of the VBA problem.

If someone could get to the event property for unbound [abc] then for the OnClick line they could enter a number that is a 2015 date *86400 but MDE should prevent that.
 

rob.low

Access Nutter
Local time
Yesterday, 23:16
Joined
Dec 27, 2007
Messages
96
Hi there merry Christmas. :D

Have you considered using the registry to store the times open and date of expiry values?
This is one of the ways how i set my trial databases that i send out.

regards :)
rob
 

NigelShaw

Registered User.
Local time
Today, 07:16
Joined
Jan 11, 2008
Messages
1,573
Hi

I was thinking registry too.

Going back to the table, what if it was deleted? What's in place?
Also

Let's say the user was savvy enough, could the user forward the date say 20yrs, install and then revert back?


Regs

Nigel
 

Mike375

Registered User.
Local time
Today, 16:16
Joined
Aug 28, 2008
Messages
2,548
Hi there merry Christmas. :D

Have you considered using the registry to store the times open and date of expiry values?
This is one of the ways how i set my trial databases that i send out.

regards :)
rob

I saw that when I first started searching on the subject. But I did not really know enough and from what I read I could stuff things up. This needs to be something that is simple as it is not so much for full DBs but packages I make that are for backup and file/folder management and where my salesman can sell without worrying about what type of person the buyer is.

FullDBs don't worry me as I ma doing them on 1/3rd deposit and another 1/3rd once there is a rough working version and the balance on completion.
 

Mike375

Registered User.
Local time
Today, 16:16
Joined
Aug 28, 2008
Messages
2,548
Hi


Going back to the table, what if it was deleted? What's in place?

If you delete the table then (in MDE) a message comes up and nothing can be done. Also, it needs the 0 in the table, which occurs each time it is run...before you can go to the program that will be used. To open the program that will be used it needs a 1 or more in the "days left" and a 0 in the field of the table.

I would of course prefer to do without the table but at the moment I can only do that if I use a macro instead of VBA. MDE stops import/export of a macro but does not prevent going to macro design and changing it.

Let's say the user was savvy enough, could the user forward the date say 20yrs, install and then revert back?

In fact if someone did that then it would block straight away. Initially, if I set the value on the OnClick line to date*86400 to be 14 days out then it would show 14 days left before anything is done. If they advanced the date on the computer, let's say 100 days then when they ran it the 14 would change to -86.

To defeat it you go the other way. If they moved the date back 100 days then after they run it the 14 days left won't change. But they must keep changing computer date everytime they use whatever the blocker is attached to. I suppose I could fix that by having the finishing date set by the first run and say based on (Date()+14)*86400 as opposed to me entering it. To do that I would have to make something that only allowed that to run once.

As a side note this business of changing the date on the computer is something you lose interest in real fast. You have to remember to change it back after each run of the program. While I was making it as you can imagine I was changing the date a lot and of course forgetting to change back. I did not realise how much stuff I use here that fouls up with date changes.

A problem that someone would have if they kept changing the date of the computer back is the date/time stamps on backups, copy folders and other file saving things in the program would foul up. Remember they have to change the date on the computer everytime they use the program and then remember to change it back when they get to the program they are going to use.
 

NigelShaw

Registered User.
Local time
Today, 07:16
Joined
Jan 11, 2008
Messages
1,573
Hi Mike,

What data are you placing in the 2 top textboxes abc and xyz? The onclick values are preset so the calculation will always be the same.

I can get your need working in vba no problem but a little more info needed please?


Nigel
 

Mike375

Registered User.
Local time
Today, 16:16
Joined
Aug 28, 2008
Messages
2,548
Nigel

[abc] has the "finish trial date" entered on the onClick line and as the date X 86400 so an entry like 3439756800

[xyz] gets the current date X 86400 so for today, 29 December it gets 3439670400

The If Then End If stops things if the current date X 86400 is < than the entry in [xyz] and hence covers winding th date back on the computer.

I could not get the IF to read anything. It would not read direcy from the macro line for OnClick or an unbound text with Date()*86400. There is no problem with a macro and its condition column, the macro condition will read direct from the entry on the onClick line.

I don't know if someting is wrong with my Access. I did Import, reboot, made a new form and also physically retyped the code but to no avail, hence I used the table.
 

NigelShaw

Registered User.
Local time
Today, 07:16
Joined
Jan 11, 2008
Messages
1,573
Hi Mike,

sorry for the questions here.

what originally places the finished trial date in the onclick event? are they added manually? if so, have you got to do this on every program you send out? i can seem to get my head around this.
you have the finish trial date placed in the abc onclick ( what puts it there ? )e )
you have the current date placed into the xyz onclick ( i can see how this is done

this can be automated much easier if i the requirement is better explained. what is this form used for? why cant this all happen as the form loads rather than clicking the label?

nigel
 

NigelShaw

Registered User.
Local time
Today, 07:16
Joined
Jan 11, 2008
Messages
1,573
Mike,

attached is a quick revamp of your need without tables. ive added a few message boxes to try and identify what is being checked. this can very easily be made into something bigger. i think you should set the date on the abc onclick to be have the value added when first run or hide a field somewhere in a table for it to check. let me know your thoughts on this.


Nigel
 

Attachments

  • FreeTrialTestingDateBasedForum (2).zip
    50.6 KB · Views: 110

Users who are viewing this thread

Top Bottom