Message Box Pops Up Before Form

JamesJoey

Registered User.
Local time
Today, 18:12
Joined
Dec 6, 2010
Messages
642
On the on Load of a form I'm checking the value of a date field.
The message box pops up fine, but before the form opens.

How do I have the form open before the message box.
I thought using SelectObject some how works but I'm not sure how.

Code:
If Me!ReminderDate > Date Then
        DoCmd.SelectObject "frmWeekViewNew"
        MsgBox "Past Due Reminders"
    Else
    End If

Now there's another problem.
I'm trying to paste the code but it won't paste.
I pressed ctl-c in access and then press ctl-v here it won't paste.
But, when I paste into Wordpad and press ctl-c it pastes fine
 
Have you tried other events? Say On Current?
 
I needed the SelectObject:

Code:
If Me!ReminderDate > Date Then
        DoCmd.SelectObject acForm, "frmWeekViewNew"
               MsgBox "Past Due Reminders"
    Else
    End If

It works ok now.
Thanks,
james
 
I now can't seem to get it to work properly.

The message box pops up regardless whether any record's date is before today.

Code:
    If Me!ReminderDate > Date Then
        DoCmd.SelectObject acForm, "frmWeekViewNew"
        MsgBox "Past Due Reminders"
    End If

Also, am I the only one having trouble pasting text here??

I'm unable to paste copied tect form Access to any of the forums I've tried.
 
What us really the isssue the msgbox or the date?
 
Well, at tis time there are no dates less than today but the message box still pops up.
 
Use less than < on your comparison.
 
Also why are you using select object?
If this code is in the form load event of that form you can remove it.

Use < as arnel said.
If the message box appears before the form opens then try one of these
1. Move it to form activate
2. Add the line DoEvents before the message box
2. Use code to delay the message box appearing e.g. Sleep command.
Google it if neessary
 
I tried that before.

Now, even though there's a date earlier than today the message box does not pop up.
 
When 'silly' things like this happen, I walk through the code line by line and inspect what each variable contains. Invariably I find it does not contain what I *thought* would be there.
 
That is because you are only comparing on the current record on your form.
To include all records for comparison use dcount() to count the number of record in your table that has
Reminderdate less than today.

Another thing use timer event of the form and not load or any event of the form. Timer event is the ladt event ( the form fully shown) of the form.
 
I should have explained further but I didn't expect it to be that complicated.

This form does not display any records from the table that I have based the form on (tblReminders)
The form is similar to a main menu.
 
Is the form showing only a SINGLE record? If not, the popup isn't doing what you want it to do. Of course that is an assumption because I don't really know what you want it to do. The point is, Events have meaning. They are not interchangeable. You need to know what you are trying to do in order to choose the correct event.

For example, if you wanted a message to display if ANY record in the form's recordset was late, then you would need to examine ALL the records, not just the first one.

Please tell us your goal and we'll help you to get the message in the correct event.
 
The form isn't showing any records.

I based the form on tblReminders so I can reference ReminderDate in tblReminders.

If ReminderDate for na record in tblReminders is less than Today (past due) I want the message box to tell me.
 
So you are trying to do a DLookup based on the earliest date in tblReminders? You don't need the form to be bound to a table for that.
 
I'm checking to see if any record's date (ReminderDate) is before today.

I want to see if there are any past due reminders.
 
Something like
Code:
DIM asWhere as String
asWhere = "ReminderDate < #" & date() & "#"
TxtFirst = nz(DLookup("ReminderDate", tblReminders, asWhere), "NONE FOUND")
DLookup returns NULL if no records match.
 
Code:
If TxtFirst <> "NONE FOUND" Then MsgBox "Your Message Here"

I was using that to demonstrate how you can use DLookup to get a result plus how you could use it to show the end user that no reminders are found. Figured you would want more than a one time message box to remind people.
 

Users who are viewing this thread

Back
Top Bottom