Print message on screen using VB

  • Thread starter KimTong via AccessMonster.com
  • Start date
K

KimTong via AccessMonster.com

Hi,

I'd like to print a message, like 'Data Error" on screen using VB when the
user enter the wrong data, e.g:

If wrongdata then
Print "Data Error"
end if


Is anybody can tell me how to write in VB? I tried to use 'Print' statement,
but it doesn't work.

Thank you in advance.

KFT
 
G

Guest

Typically, you use a Message Box to display messages like this.
If wrongdata then
MsgBox "Data Error"
end if

You can also put messages in a Label Control if you don't want a message box
to pop up.

If wrongdata then
Me.lblMessage = "Data Error"
End If
 
K

KimTong via AccessMonster.com

Thank you Klatuu, it works. And how can I move the cursor move back the same
field?. Because after the error message comes up the cursor move to the next
field.

KFT
Typically, you use a Message Box to display messages like this.
If wrongdata then
MsgBox "Data Error"
end if

You can also put messages in a Label Control if you don't want a message box
to pop up.

If wrongdata then
Me.lblMessage = "Data Error"
End If
[quoted text clipped - 12 lines]
 
G

Guest

If you are validating entry in a control, then you use the control's Before
Update event. The Before Update can be Canceled. If the validation fails,
canceling the event prevents the update from occurring and leaves the cursor
in the control:

Private Sub MyControl_BeforeUpdate(Cancel As Integer)

If wrongdata Then
Cancel = True
MsgBox "Data Error"
End If

End Sub
--
Dave Hargis, Microsoft Access MVP


KimTong via AccessMonster.com said:
Thank you Klatuu, it works. And how can I move the cursor move back the same
field?. Because after the error message comes up the cursor move to the next
field.

KFT
Typically, you use a Message Box to display messages like this.
If wrongdata then
MsgBox "Data Error"
end if

You can also put messages in a Label Control if you don't want a message box
to pop up.

If wrongdata then
Me.lblMessage = "Data Error"
End If
[quoted text clipped - 12 lines]
 
K

KimTong via AccessMonster.com

Hi,

I did try before using control After Update, something like this:

If wrongdata Then
MsgBox "Data Error"
Me.fieldname.??? ---> go back to the same field.
End If

But I forgot how to write it. If you have any other any idea, I am
appreciated.

KF
If you are validating entry in a control, then you use the control's Before
Update event. The Before Update can be Canceled. If the validation fails,
canceling the event prevents the update from occurring and leaves the cursor
in the control:

Private Sub MyControl_BeforeUpdate(Cancel As Integer)

If wrongdata Then
Cancel = True
MsgBox "Data Error"
End If

End Sub
Thank you Klatuu, it works. And how can I move the cursor move back the same
field?. Because after the error message comes up the cursor move to the next
[quoted text clipped - 19 lines]
 
G

Guest

Re-read my previous post. It is the Before Update. The After Update is too
late.
--
Dave Hargis, Microsoft Access MVP


KimTong via AccessMonster.com said:
Hi,

I did try before using control After Update, something like this:

If wrongdata Then
MsgBox "Data Error"
Me.fieldname.??? ---> go back to the same field.
End If

But I forgot how to write it. If you have any other any idea, I am
appreciated.

KF
If you are validating entry in a control, then you use the control's Before
Update event. The Before Update can be Canceled. If the validation fails,
canceling the event prevents the update from occurring and leaves the cursor
in the control:

Private Sub MyControl_BeforeUpdate(Cancel As Integer)

If wrongdata Then
Cancel = True
MsgBox "Data Error"
End If

End Sub
Thank you Klatuu, it works. And how can I move the cursor move back the same
field?. Because after the error message comes up the cursor move to the next
[quoted text clipped - 19 lines]
 
K

KimTong via AccessMonster.com

Yes, it works. Than you very much...

KFT
If you are validating entry in a control, then you use the control's Before
Update event. The Before Update can be Canceled. If the validation fails,
canceling the event prevents the update from occurring and leaves the cursor
in the control:

Private Sub MyControl_BeforeUpdate(Cancel As Integer)

If wrongdata Then
Cancel = True
MsgBox "Data Error"
End If

End Sub
Thank you Klatuu, it works. And how can I move the cursor move back the same
field?. Because after the error message comes up the cursor move to the next
[quoted text clipped - 19 lines]
 

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