I don't know how to do this -please help

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi,

I am trying to do the following but don't know how:

on my from I have:
currentMileage
PrevMileage

I want to subtract PrevMileage from CurrentMileage and if
the result >=3000, display a message that service is
overdue. I know how tyo setup the expression for the
subtraction, but don't know where to put it and how to
make/immplement the message box to disply the desired
message.

Thank you in advance.

Mike
 
Hi Mike,

If you want a messeage box to pop up, it's best to do it in VBA.
Within your "If" expression, use the "MsgBox" command.
So put this code within either a command button as onClick, or afterUpdate
on one of your field.
An example would be:

Private Sub butt_Click()

Dim result As Integer

result = Me.currentMileage - Me.PrevMilage
If (result >= 3000) Then
MsgBox ("Service Overdue")
Else
MsgBox ("Service Not Due")
End If

Me.result = result

End Sub

In the above example, I have put in a button for initiating the calculation,
and also a text box control called "result" to display the calculation

Alex
 
Alex,
Thanks for your prompt and to the point response. I
wanted to ask you another question if its not too much
please, I was wondering if I could change the font and
color of the MsgBox in the code or not?

Thank you in advance.

Mike
 
Mike
Only if you change the global settings for the computer.
This will effect all programs running on your computer.

Right-click on a blank portion of the Windows Desktop.
Select Properties.
Click on the Appearance tab.
Find the Message Box in the drop down.
Make your changes and then exit.

Why not just make your own unbound form to act as a message box.
You would use
DoCmd.Openform "FormName", , , , , acDialog
to open the form.
 
Thanks, and this make sense. where should I place this
code? currently I have put the following code on the
AfterUpdate of the PrevMileage field on the form.

The code is as follow
Private Sub butt_Click()

Dim result As Integer

result = Me.currentMileage - Me.PrevMileage
If (result >= 3000) Then
MsgBox ("Service Overdue")
Else
MsgBox ("Service Not Due")
End If
Me.result = result
End Sub

Should I replace the MsgBox ("Service Overdue") and
("Service Not Due)

with

DoCmd.Openform "FormName", , , , , acDialog

??

Thank you in advance for your help.

Regrads,

Mike
 
Hello again,

Is it possible to have the code to insert a text in one
of the feilds on the form as well?

Regards,

Mike
 
Mike,

Is this the same message box form in this thread?

How are you opening the form?
You can't directly if you open the form in dialog, as
processing stops until you close the form.
However, you can open the form first in Design View,
make the change, close it and then reopen it in Dialog
using some code:

DoCmd.OpenForm "FormName", acDesign
Forms!FormName!ControlName.ControlSource = "= 'This is some text'"
DoCmd.Close acForm, "FormName", acSaveYes
DoCmd.OpenForm "FormName" , , , , , acDialog

Notice the use of single and double quotes in the control source text above.
The change made to 'FormName' is now part of the form, and
will be there the next time you open the form, unless changed,
perhaps in the dialog forms Close event. Your choice.

The above assumes [ControlName] is a Text control, not a label control.
If you are using a label control then use:
Forms!FormName!ControlName.Caption = "This is some text"


If you are opening the form in Normal view, not in dialog,
then something like this will work.

forms!FormName!ControlName = "This is some text"

The above assumes [ControlName] is a text control, not a label.
If it is a label control, then

forms!FormName!ControlName.Caption = "This is some text"

In this case you are setting the control's Value property.
In the previous example above you were setting the control's
ControlSource property.
The Form must be open when this code is run.
 
Fred,

It worked as suggested by you. Thanks much.

Mike.
-----Original Message-----
Mike,

Is this the same message box form in this thread?

How are you opening the form?
You can't directly if you open the form in dialog, as
processing stops until you close the form.
However, you can open the form first in Design View,
make the change, close it and then reopen it in Dialog
using some code:

DoCmd.OpenForm "FormName", acDesign
Forms!FormName!ControlName.ControlSource = "= 'This is some text'"
DoCmd.Close acForm, "FormName", acSaveYes
DoCmd.OpenForm "FormName" , , , , , acDialog

Notice the use of single and double quotes in the control source text above.
The change made to 'FormName' is now part of the form, and
will be there the next time you open the form, unless changed,
perhaps in the dialog forms Close event. Your choice.

The above assumes [ControlName] is a Text control, not a label control.
If you are using a label control then use:
Forms!FormName!ControlName.Caption = "This is some text"


If you are opening the form in Normal view, not in dialog,
then something like this will work.

forms!FormName!ControlName = "This is some text"

The above assumes [ControlName] is a text control, not a label.
If it is a label control, then

forms!FormName!ControlName.Caption = "This is some text"

In this case you are setting the control's Value property.
In the previous example above you were setting the control's
ControlSource property.
The Form must be open when this code is run.

--
Fred

Please reply only to this newsgroup.
I do not reply to personal e-mail.


Mike said:
Hello again,

Is it possible to have the code to insert a text in one
of the feilds on the form as well?

Regards,

Mike
do
it CurrentMileage
and how
to


.
 
Back
Top