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

MsgBox not displaying - code included 1

Status
Not open for further replies.

lmmoorewi

IS-IT--Management
Feb 5, 2009
24
0
0
US
Ican't figure out why the Msgbox does not appear. What am I doing wrong?

If the Status field on the Worksheets form is set to 'Approved', I want the form to open, but I also want a Msgbox informing the user that they can't edit the form.


Here is my code:
If "Worksheets.Status" = "Approved" Then
DoCmd.OpenForm "Worksheets", acNormal, , strWhere, acFormReadOnly, acWindowNormal
Msgbox "Unable to edit 'Approved' Reports"
Else

DoCmd.OpenForm "Worksheets", acNormal, , strWhere, acFormEdit, acWindowNormal

 
If [!]"[/!]Worksheets.Status[!]"[/!] = [!]"[/!]Approved[!]"[/!] Then
The 2 strings literals are ALWAYS different !

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How are ya lmmoorewi . . .

If [blue]Status[/blue] is truly on the [blue]WorkSheets[/blue] form then your trying to access [blue]Status[/blue] before [blue]WorkSheets[/blue] is open!

As a first stab at this I think you should have:
Code:
[blue]   Dim frm As Form
   
   DoCmd.OpenForm "Worksheets", acNormal, , strWhere
   DoEvents [green]'allow time for the form to open![/green]
   Set frm = Forms!Worksheets
   
   If frm!Status = "Approved" Then
      frm.AllowEdits = False
      MsgBox "Unable to edit 'Approved' Reports"
   End If

   Set frm = Nothing[/blue]

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Hey TheAceMan1 -

Well, you have done it again. Reading from the bottom up on replies, I tried your code first and it worked.

You were right, I was trying to access Status before the form was open.

You would not believe how long I have searched for a solution to this issue. :(

Thanks again for your response and solution!
 
Another quick question about this issue...I would say I promise, but that may not be true. :)

If I need to check for another field on that form (Worksheets) and display a message box, is this correct?

I am just loading the Worksheets form and if the WeekEndingDates field is blank, I wwant the "Report Does Not Exist' message to display.

DoCmd.OpenForm "Worksheets", acNormal, , strWhere
DoEvents 'allow time for the form to open!
Set frm = Forms!Worksheets

If frm!Status = "Approved" Then
frm.AllowEdits = False
MsgBox "Unable to edit 'Approved' Reports"
End If

If frm!WeekEndingDates = "" Then
Msgbox "Report Does Not Exist"
End If
Set frm = Nothing
 
lmmoorewi said:
[blue]If I need to check for another field on that form (Worksheets) and display a message box, is this correct?[/blue]
You've already proven you can check any [blue]field(s)[/blue] you like! ... So why not! [surprise]

However ... for what you shown, I would simply:
Code:
[blue][purple]Change:[/purple]
   If frm!WeekEndingDates = "" Then
[purple][b]To:[/b][/purple]
   If Not [purple][b]IsDate([/b][/purple]frm!WeekEndingDates[purple][b])[/b][/purple] Then[/blue]
Its just better logic for your purpose!
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Yay! You Rock!!

Thanks again for your help on the db.

 
Anyway, why not use the Current event procedure of the form ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top