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

Memo fileld - can it be set 1

Status
Not open for further replies.

Dophia

Technical User
Jul 26, 2004
263
CA
Hi Everyone: I'm using Access 2003. The text field of 255 is not large enough and I want to double it to about 500. Can I set a size in the Memo field, without running VBA to tell the user that they are limited. For example, a text field only lets you enter 255 characters. That is what I want to do with the memo field....only enter 500 characters and have the program not let you enter more.

Thanks for any help,
Sophia
 
What would you suggest then? Is there a way to let the person entering data know that they are close to a set maximum number of characters? Or do they just know it once they leave the field?
 
I am sorry, but as I already stated there is no way to limit the amount of inputs into a memo field or provide a message without using vba. Since vba is not an option for you there is no solution.

The only way to do it would require using vba on a form to check the length of the string using the on change event. Prior to reaching the established limit on the string you would provide a message and lock the field once the limit is met.
 
Thank you MajP. I see that that will be the only solution. Can you assist me in doing this? Any help or guidance would be appreciated.

Thanks, Sophia
 
Pass in the textbox, the message limit, and the text box limit
Code:
Public Sub limitInput(txtBx As Access.TextBox, MessageLimit As Long, textLimit As Long)
   Dim textCount As Long
   Dim strTemp As String
   textCount = Nz(Len(txtBx.Text))
   If textCount = MessageLimit Then
     MsgBox "This field is limited to " & textLimit & " you are currently at " & textCount
   ElseIf textCount >= textLimit Then
     MsgBox "You have reached the limit " & textLimit & " characters."
     strTemp = txtBx.Text
     Me.Dirty = False
     txtBx.Text = Left(strTemp, Len(strTemp) - 1)
   End If
End Sub
call from the change and got focus event
Code:
Private Sub Notes_Change()
  limitInput Me.Notes, 10, 20
End Sub
Private Sub Notes_GotFocus()
  limitInput Me.Notes, 10, 20
End Sub
I am limiting the textbox "Notes" to 20 characters with a message at 10.
Practice on dummy form before doing it on yours.
 
Sorry to disagree, MajP, but there most certainly is a way to accomplish the limit without using VBA as the poster requested. Just use a macro.

As you suggested, it would be fired either on the OnChange or BeforeUpdate events of the control in question. The condition field of the macro would be Len([ControName])>500, and it would have two operations. The first is a MsgBox that would give the appropriate warning, the second would be an Undo command.
 
Thank you MajP. It works perfectly, except the line......

" Me.Dirty = False" ...It is an invalid use of "me".


Can you help me with what should be replaced there?
Thank you,
Sophia
 
Seems like your form isn't bound.
So, just comment out this line.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Should all of the above code be in the form or should some be in the public modules?

Sophia
 
The procedure was designed to be placed in a standard module. That way you can call it from multiple forms without having to rewrite the code. If you place it in a forms module then only that form can use it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top