Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Allowing Text Fields only

Status
Not open for further replies.

sclary34

MIS
Jan 28, 2002
8
US
I have a form that allows a user to right click on highlighted text and make changes to the data. The form has several fields with types including text, memo, and numeric. I don't want the user to be able to change numeric fields. I would like them to get prompted with a MsgBox if they attempt to right click on a numeric field. Here is the code that grabs the string and converts it. Does anyone know how to do this?

Set frmForm = Screen.ActiveForm
Set ctlActive = Screen.ActiveControl

With ctlActive

DoCmd.SetWarnings (False)
strRedacted = .SelText
intPosition = InStr(ctlActive.Value, strRedacted)
strLeft = Left(ctlActive.Value, intPosition - 1)
strRight = Right(ctlActive.Value, Len(ctlActive.Value) - ((intPosition - 1) + Len(strRedacted)))

strRedacted = String(.SelLength, 167)
 
If I understand what you want (I don't know what your code excerpt has to do with it), you just need to set each of the numeric field controls to Enabled and Locked. Enabled allows the control to accept keyboard and mouse events so they can click on it, but Locked prevents the user from modifying the contents. Each numeric field control then needs to have its On Mouse Down property set to "=NumMsg()". The NumMsg function is coded in the form module, and looks like this:
Code:
Private Function NumMsg(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If (Button And acRightButton) Then
        Beep
        MsgBox "Please don't right-click numeric fields"
    End If
End Function
You could use a similar technique for the text and memo controls to call a function that contains your code excerpt above. Of course, you would not set these controls to Locked, since you want the user to be able to edit them. Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top