message box syntax error

J

Janis

I have a form with 3 option buttons with different procedures in each. If
the user picks option 1 then I want it to do 2 procedures and give the user a
message box. Something is wrong with the message box. I just want it to
print a message with the report date from two globally declared variables.
frRptDate and toRptDate. This is the onclick procedure.



Private Sub Okay_Click()
If optionButton1.Value.true Then
msg.box( "From:" & frRptDate &"To:" &toRptDate,vbCritical,"Report Date")
Private Sub deleteDateRow1()
Private Sub ckForDupesMac()
Else
OptionButton2.Value.true
xxxxx()
Else
OptionButton3.Value.true
xxxxx()
End If
End Sub
 
J

jpdphd

Janis,
i think the format should be

Response = MsgBox("From:" & frRptDate & "To:" & toRptDate, vbCritical,
"Report Date")
 
J

JE McGimpsey

Janis said:
I have a form with 3 option buttons with different procedures in each. If
the user picks option 1 then I want it to do 2 procedures and give the user a
message box. Something is wrong with the message box. I just want it to
print a message with the report date from two globally declared variables.
frRptDate and toRptDate. This is the onclick procedure.

Couple of things:

1) You can't just make up your own object syntax (well, you can, using
classes, but I don't think that's what you're trying to do). The
optionButton1 object has a .Value *property*, not a .Value child object.
There is no .True property, so

If optionButton1.Value.true Then

is properly written

If optionButton1.Value = True Then

Note that the "= True" part will be implied by the compiler if you leave
it out, so you *could* just use

If optionButton1.Value Then

but I *strongly* recommend against doing that, for readability and
maintenance purposes. It doesn't make your code execute any differently.

2) Be careful that you look at the correct syntax, i.e.:

MsgBox

not

msg.box


3) You can't declare functions within another function. The keywords
"Private Sub" declare functions rather than calling them. Instead of
declaring them:

Private Sub deleteDateRow1()
Private Sub ckForDupesMac()

you should instead call them by their procedure name:

Call deleteDateRow1
Call ckForDupesMac

Note that "Call" is optional, you could also use

deleteDateRow1
ckForDupesMac

Using the parens afterward isn't an error, but isn't necessary either
unless the functions have arguments, and you use the Call keyword.

So I think what you're looking for would be better coded as:

Private Sub Okay_Click()
If optionButton1.Value = True Then
MsgBox Prompt:="From: " & frRptDate & _
vbNewLine & "To: " & toRptDate, _
Buttons:=vbCritical, _
Title:="Report Date"
deleteDateRow1
ckForDupesMac
Else
optionbutton2.Value = True
'xxxxxxx()
End If
End Sub
 
J

Janis

Thanks for your help with the forms. It helped since I had some problems
with the personal workbook this morning I had to recreate everything in a
general module. I cannot save my personal workbook anymore. It is
corrupted. Only a few more days of this and I am done. If you happen to get
this reply, I have another question re the declaring variables:
dim FrReptDate as date
dim ToRepdate as date
I declared these variables already in the declaration section of a module in
the project. I want them to save the value since I have to later reformat
this whole thing after I use it as a database. Here I am using these
variables I already set the values. So I don't have to redefine the
varaibles do I? I think I just have to call them in the macro and it will
get the value I declared earlier?

thanks,
 
J

JE McGimpsey

Janis said:
If you happen to get
this reply, I have another question re the declaring variables:
dim FrReptDate as date
dim ToRepdate as date
I declared these variables already in the declaration section of a module in
the project. I want them to save the value since I have to later reformat
this whole thing after I use it as a database. Here I am using these
variables I already set the values. So I don't have to redefine the
varaibles do I? I think I just have to call them in the macro and it will
get the value I declared earlier?

With global variables such as you've declared, the value assigned is
maintained as long as the VBE environment is running, so no, you don't
have to redefine the values.

In fact, if you Dim the variable inside a procedure, it creates a new
variable that is used within that procedure without affecting the global
variable. See VBA Help's "" topic for more.

As an example, paste this into a module and run StartOff:

Dim a As String

Public Sub StartOff()
a = "Value assigned in Startoff"
MsgBox "Sub Startoff: " & a
foo1
MsgBox "Sub Startoff: " & a
foo2
MsgBox "Sub Startoff: " & a
End Sub

Public Sub foo1()
Dim a As String
a = "Value assigned in foo1"
MsgBox "Sub foo1: " & a
End Sub

Public Sub foo2()
a = "Value assigned in foo2"
MsgBox "Sub foo2: " & a
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top