Auto Fill In

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I have a text box that is used to enter yes or no. I want the user to have
the ability to just enter a y or n hit enter and yes or no will be there. I
know about using a combo box and value list. However, I am looking for a way
to do this programmatically with the text box. This will appear much cleaner
in my form for the users without the drop down arrow. Any ideas??

BD
 
Sure, try something like this (aircode):

Sub txtMyControl_Change()
Select Case txtMyControl
Case "y"
txtMyControl = "Yes"
Case "n"
txtMyControl = "No"
Case Else
MsgBox "You must enter a "y" or an "n", vbOKOnly, "Data rule"
End Select
End Sub

Add some error handling and you're home free.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
Bruce

Try the code that I use. Paste this function code into a module.

Public Function CheckYesNo(vValue As String) As String

'Returns 'Yes' or 'No' if user enters Y or N or '' for anything else
'Entry (vValue) = Value in field
'Exit (CheckYesNo) = Y or N or blank

Select Case UCase(vValue)
Case "Y"
CheckYesNo = "Yes"
Case "N"
CheckYesNo = "No"
Case Else
CheckYesNo = ""
Beep
MsgBox "ERROR. Please enter Y (Yes), N (No) in this field.",
vbCritical + vbOKOnly, "Invalid Entry"
End Select

End Function

In the Change event of your text boxes enter :-

txtFieldName = CheckYesNo(txtFieldName.Text)

where txtFieldName is the name of your field. Now when the user presses Y or
N the field will immediately change to Yes or No. If they press any other key
an error message is displayed and the field is blanked out.

HTH
 

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

Similar Threads

Auto Fill In 1
Auto fill not working 2
Auto Update Text box 1
Auto fill of fields 4
Text Auto Fill 1
Continuous Form Auto Fill In 1
Combo Box allows blanks 2
Auto Number Fill 3

Back
Top