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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textbox - force user to type something

Status
Not open for further replies.

andzejek

MIS
Sep 1, 2007
154
US
Hi!

On a form I have few textboxes and one of them must be filled with some text. How to force user to type something in this texbox?

Andrew
 
In table design, select the text field you need filled in and set the required field value in the general tab as yes. That should mean that the user has to enter something, rather than leave the field blank.
 
or in the forms BeforeUpdate event:
Code:
[blue]   Dim Msg As String, Style As Integer, Title As String, DL As String
   
   DL = vbNewLine & vbNewLine
   
   If Trim(Me![purple][b][i]TextboxName[/i][/b][/purple] & "") = "" Then
      Msg "'[purple][b][i]TextboxName[/i][/b][/purple]' is Required!" & DL & _
          "Enter data or hit 'Esc' to abort the record . . ."
      Style = vbInformation + vbOKOnly
      Title = "Missing Data Error! . . ."
      MsgBox Msg, Style, Title
      [b]Cancel = True[/b]
      Me![purple][b][i]TextboxName[/i][/b][/purple].SetFocus
   End If[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
domino3 - I don't have option "required field".

TheAceMan1 - I'm getting error message: Run-time error '2108': You must save the field before you execute the GoToControl action, the GoToControl method, or the SetFocus method.

This textbox is unbound.
Thank you.
 
If you are using access, you need to be in that table that the form is bound to. If you open that table in design view, and look down the list of fields available, select the field you need. Then look towards the bottom half of the screen to where there are two tabs, one says general and the other says lookup. There will be a list of properties such as field size and format. Click on the one that says required, which should be about three quarters of the way down the list. An arrow should appear, giving you the option of yes or no.
 
Are you sure you want the textbox unbound? If you do, then I think you will get the same data on all the records showing in your form.
 
Yes, I want this textbox unbound - input from this textbox I'm using as a parameter for tables updates.
 
You need to have a command button on the form which runs a query with

[Forms]![F_name of form]![name of text field]

as the query parameter.

To run the form, you fill the text into the unbound text box, click the command button you created and the text you typed in is picked up via the command button in the query and returns the results you want.

Hope that makes sense.

 
andzejek . . .

Add the line in [purple]purple[/purple] where you see it:
Code:
[blue]   DL = vbNewLine & vbNewLine
   [purple][b]If Me.Dirty Then Me.Dirty = False[/b][/purple][/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Still does not work.
1st - "beforeupdate" isnot triggered if nothing is typed in the box. You can go into the box and tab out without any action in "beforeupdate.
2nd - on setfous error message is popping up: Run-time error 2108: you must save the field before execute GoToControl action, GoToControl method oe SetFocus method.

Andrew
 
I am running access 2000 and when I create a command button with the toolbox wizard on, then the code is created for me.

In access 2000 you shouldn't need anything in the before update on the form itself. The wizard should let you position the button where you want it, then give you the choice of what you want it to do. You need to choose to run a query, choose the query you want, and then decide what you want to call it.

I don't know whether all versions to that, though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top