OpenArgs issue..

mloucel

Member
Local time
Today, 15:39
Joined
Aug 5, 2020
Messages
263
Hello Gurus.

I am doing a simple test with OpenArgs [Learning]

I am creating a very simple Customized MessageBox, something so simple without any extreme or complicated code.
since it will be a message box, must be MODAL by default so that the user is forced to click YES or NO.

So I found out I need to use "OpenArgs" in order to transfer 2 simple messages to my box
1) The title of the warning [So I can change it, any time, or leave the default]
2) The message of the warning. [I can write whatever I want to the End User]

My Problem:
when I do the OpenArgs split, I have no idea why only the message of the warning is displayed, and the title displays the Variant Name instead of the Value.
I have a few MsgBox to see what is being transferred and I cannot figure out where is the error, I've been trying already for 5 hours and I thing my brain is burned now and I can't see beyond my own nose.

I know all of you will be able to see the error in 10 seconds, so please kindly let me know where is my error.

I have attached my test DB as it is now.

Thanks in advance.
 

Attachments

I think it could be a whole lot simpler.
Code:
Public Function MMB(Promptt As String, Optional WarnMessg1 As String)
    ' Pass the Args variables we will use in the box
    Dim Args As String
    Args = Promptt  ' do not know why you want the =
    If WarnMessg1 <> "" Then Args = Args & ";" & WarnMessg1
    DoCmd.OpenForm "MessageBoxF", WindowMode:=acDialog, OpenArgs:=Args
End Function

I would simply concatenate the ars as someprompt;SomeMessage
You made it overly complicated with the = signs

No idea about your loop. I do not see the need.
they have to pass at least the prompt so no need to check for args(0) it has to be there.

Code:
Private Sub Form_Load()
    DoCmd.MoveSize 12500, 5500
    Dim Args As Variant
    Dim NameValue As Variant
    Dim x As Long
    
    Args = Split(Me.OpenArgs, ";")
    'Debug.Print Args(0)
    'Debug.Print Args(1)
  
    Me.WarnMessg.Caption = Args(0)
    If UBound(Args) = 1 Then Me.Prompt.Caption = Args(1)
End Sub
 
I also demoed a way to return values from pop up.
 

Attachments

I also demoed a way to return values from pop up.
Thanks for the Demo, I just had to change the order and it works, yep simple and efficient, I will get it as a teaching experience, now part of the code I create was because the "WarnMessg" label could have dual purpose, hence is Optional, the idea in my head is the Warning Label, is standard "WARNING" but from time to time I may need to change it to something else, so if I don't use the parameter then it should display the "Standard" label, if not I change the caption of the label to whatever suits me at that time.
so I am going to fix the code so that I don't get a subscript out of range error.
Or just keep both is just 1 simple line.

But yes, thank you, this is supposed to be this simple, nothing complicated, I hope in the not-so-distant future someone else can see this and appreciate and use the simplicity of the form.

Thank you so much.

Maurice.
 
If you are only returning two states you can shorten the code a bit...
Thank you as well, yes most message boxes do not require painful and complicated code, yes I've seen some very wonderful things you can do, but most of us, simply want to display a Message Box that displays a message and a warning or exclamation about something, all other examples I've seen are really wonderful using all the resources from windows, access, etc., but I wanted something simple and straight to the point, this code does it.
I hope someone finds it useful as well.

Thanks

Maurice.
 

Users who are viewing this thread

Back
Top Bottom