Newbie questions

Liquid

New member
Local time
Today, 13:58
Joined
Nov 23, 2006
Messages
2
Hi,

I have a few simple questions:

I have a form for employees that contains their salaries. How would I go about creating a macro that would cause a warning box to display any time a salary greater than $100,000 is entered?

On the same employee form I have a textbox to input the email address. After you input the email I want a lostfocus event to check if it follows the same format as "username@email.com" If it wouldn't match that format an error message will be shown.
 
Hi,

First question: I sincerely hope the salary-field is numeric in nature, else this won't work (change Field1 with your fieldname ofc):

Private Sub Field1_LostFocus()
If Me.Field1.Value > 100000 Then
MsgBox "Warning! The salary is above $ 100,000!", vbCritical, "Warning! High salary!"
End If
End Sub


Second question:

Private Sub Field1_LostFocus()
If InStr(1, Me.Field1.Value, "@") = 0 Then
MsgBox "No @ detected in e-mail address."
End If

If InStr(InStr(1, Me.Field1.Value, "@") + 1, Me.Field1.Value, ".") = 0 Then
MsgBox "No . detected in the domain of the e-mail address."
End If
End Sub

Hope this works for you! :)
 
Alternatively,

First question -

You can use the validation rules and messages in table design for that field.

Second question -

You can set up an input mask and error message to ensure correct format is entered.

Col
 
Is it possible to find out if the salary is > 100000 using a macro and no VBA code?

The email one is working great, thanks.

Also on a form if I have a value in a textbox and I want to multiply that number with another value that is not on the form, but in a table, how would I do that? I have a table that lists different items that have different prices. On the form I have the name of the item, but not its price. And in the item table, it has the price of the corresponding item in the same row. (hopefully this got understood) I would put me.fieldname.value * ??? then I'm not sure how to match the item name and call that itemprice?
 
hi liquid. i think most users here would recommend using code rather than macros - easier to control, write and more flexible. i think the only thing you can do in macros that you cant do in code is autokeys
 

Users who are viewing this thread

Back
Top Bottom