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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On-timer Code doesn't work

Status
Not open for further replies.

CSHANKY

IS-IT--Management
Jun 4, 2003
20
US
I have created this little database and hosted it on a network drive. Since its a multi-user db, many users open it and conviniently forget to close it. Needless to add, this slows the system and no admin stuff can be done, if needed.

Can I make the system automatically figure out it hasn't been used for 3 mins and close the application, silently.....(Yes, thats the way I want it. No messages, nothing - close the DB entirely, infact, exit Access if possible)
-------

I tried the "brutal" way suggested on Thread702-627282 which suggested:

1. Create a table (table1) with one yes/no field set to true. (so I created a table1 and added record with "yes")

2. Create an unbound form (form1). You can open this form as hidden in your AutoExec macro. (done)

3. On Timer event place this code:


Private Sub Form_Timer()
Static MsgSent As Integer
Dim LogOff As Integer
Dim db As Database
Dim LO As Recordset

Set db = CurrentDb()
Set LO = db.OpenRecordset("table1", DB_OPEN_SNAPSHOT)

LO.MoveFirst
LogOff = LO!LogOff
LO.Close
db.Close

If LogOff = True Then
If Not MsgSent Then
MsgBox "The application will terminate in One Minute for maintenance. Please logg off immediately"
Me.TimerInterval = 600000
MsgSent = True

Application.Quit

End If
End If
-----
Did all that too - but it doesn't work ! I get an error message saying

"The Expression you entered on On Timer Even Property .....error: User-defined type not defined."

Can someone PLEASE help ?

----
Then I tried the second, elegant option on Thread702-627282 and got:

"The expression On Timer you entered...produced error:Sub or function not defined"
-----
Where am I going wrong ??? Someone, ANYONE, please help.....
Does the code need some debugging ?


Note: I am no programmer
 
I would help if you also stated which line gave the error.

Guessing it's the dim db as database - if so

1 - set a reference to the Microsoft DAO 3.# Object Library (in any module Tools | References)
2 - explicit declaration

[tt]Dim db As DAO.Database
Dim LO As DAO.Recordset[/tt]

Roy-Vidar
 
Hi ! Sorry - I am quite unfamiliar with programming.

I do not know how to:

"set a reference to the Microsoft DAO 3.# Object Library (in any module Tools | References)"

Could you give me a step-by-step guide ?

I did however change:
Dim db As DAO.Database
Dim LO As DAO.Recordset

Didn't work ! :(

 
It's kind of step by step above

In any module - that's where the code is

Find the "Tools" menu, select "References"

In the references dialog, find Microsoft DAO 3.# Object Library and set a checkmark in front of it, then press OK. # representing a number, probably 6, but choose the highest number available. Should after this also use the Debug menu and chose compile.

Declaring/using objectvariables from the DAO library requires the Library to be checked - thus available.

Roy-Vidar
 
Did that !

Now it says:

Runtime erro "3265"

Opening the debugger highlights:

LogOff = LO!LogOff
 
Don't know the error codes by heart. I can't se whether you have a field in "table1" called LogOff or if it's datatype, if it exists, is compatible with the variable LogOff or if the field contains a Null value.

Roy-Vidar
 
I got it. So what I needed to do was name the yes/no field in Table1 as "LogOff" and it works.

Thanks a PILE Mr. V....for helping the hoplessly lost lesser mortals (read non-programmers)....

I owe big time to the folks in Tek-tips....


 
Thanks ! :) Much appreciate it....

However, would you know how I could modify it so that:

It closes the application silently (no warnings, nothing) afet 5 minutes of inactivity.


Rgds

Shanky
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top