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

Close Form With Timer

Status
Not open for further replies.

jbento

Technical User
Jul 20, 2001
573
US
All,
I would like to close a form with a timer set to 1 sec when it opens based on if a specific field is empty. How would I do that?

Example: If frm_main opens and field1 is empty I want frm_main to close in 1 sec when opened.

What would be the code for this?

Thanks for the help?

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
danvlas shows the backend, and so I'll offer an option for the front end.
Code:
Private Sub Form_Load()

   If (Nz([field1], "") = "") Then
      TimerInterval = 1000
   Else
      TimerInterval = 0
   End If

End Sub

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thanks my friends.

I will try this at work today:)

YOU ALL HAVE A WONDERFUL BLESSED HOLIDAYS!!!!

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
After further review, the ruling in the thread has changed.

danvlas - uses a different approach than I was thinking. In that approach, the timer will always fire after 1 second, and then field is checked against Null and the form closes accordingly. However, the conditional does not take into account the possibility (if it exists) of field1 being an empty string ("")

My approach check the value of the field and if either Null or an Empty String activates the Timer. But I don't show the Timer code, which should be as follows:
Code:
Private Sub Form_Timer()
   DoCmd.Close acForm, Me.Name
End Sub

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
YOU ALL ARE AWESOME!!!!

It worked BEAUTIFULLY!!!

Have a HAPPY HOLIDAY!!!

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
Cajun,

There are many ways to skin the same cat. I guess the main idea was what Jerome was looking for, and now he has two: 1: having the Timer property set in form design
2: setting the property on loading the form.

I don't consider a field containing a zero-length string as being empty, that's why I used IsNull. There are (many) cases when I fire different lines of code depending on whether a field is Null or ""...

Cheers,


[pipe]
Daniel Vlas
Systems Consultant

 
I agree completely. There are many ways to do the same thing, with pros and cons each way.

And I also agree that zero-length string is not the same as a null string. Unfortunately, throughout these forums, I've see a distressing number of people who do not understand that they are different, much less, understanding just what the difference is.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top