Limit text box to any character except \, /, :, ?, <, >, !

Hello-
I am currently working in a form which contains a text box that a user will
use to create a job number and another text box for the job name. Later in
the same form, the user will have the ability to create certain directories
based upon this job number and another directory based upon the job name.  I
would like to put a function behind the after_update event of each event that
will review this text box and make sure that the string entered does not
contain any character that would cause a conflict when creating a directory,
namely the following \ / : ? < > ! characters.  

What would be the best approach to creating this code?

Thank you in advance.
Chris

-- 
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200803/1

0
SurveyorinVA
3/17/2008 4:53:39 PM
access.formscoding 7493 articles. 0 followers. Follow

3 Replies
1067 Views

Similar Articles

[PageSpeed] 39

Hi - 

I use this function to do what you are looking for:

Function Valid_Field_Name(NameText As Variant) As Boolean
   Dim K As Integer ' loop counter
   Valid_Field_Name = True
   For K = 1 To Len(Trim(NameText))
     If InStr(".!`[]""", Mid(NameText, K, 1)) <> 0 Then
       Valid_Field_Name = False
       Exit Function
     End If
   Next K
   
End Function


I use it like this:
   '
   ' check for non-valid characters in the column name
   '
   If Not Valid_Field_Name([text8]) Then
     FormattedMsgBox "The column title contains character(s) that are not
valid.@" & _
        "The column name cannot contain a period (.), exclamation point (!),
accent grave (`), square brackets ([]) or double quotes ("")@ ", , "Column
Name is not valid"
     Cancel = -1
     Exit Sub
   End If


You might want to put the check in the Before Update or On Exit event of your
control, so that you can take advantage of the Cancel = -1 to cancel the
event.

These could easily be modified to suit your purposes.  FormattedMsgBox is a
function used to provide a message box (3 parts to the text) in the old
format of Access 97, i.e. one bold and 2 normal paragraphs:

Function FormattedMsgBox( _
    prompt As String, _
    Optional buttons As Variant = vbOKOnly, _
    Optional title As String = "PC - CODAP", _
    Optional HelpFile As Variant, _
    Optional context As Variant) As Integer
    
    Dim strMsg As String, quote As String
    Dim sTemp As String
    sTemp = strtran(prompt, """", """""")
    quote = Chr(34)
    
    If IsMissing(HelpFile) Or IsMissing(context) Then
       strMsg = "msgbox(" & _
       quote & sTemp & quote & _
       ", " & buttons & _
       ", " & quote & title & quote & _
       ")"
    Else
       strMsg = "msgbox(" & _
       quote & sTemp & quote & _
       ", " & buttons & _
       ", " & quote & title & quote & _
       ", " & quote & HelpFile & quote & _
       ", " & context & _
       ")"
    End If
    FormattedMsgBox = Eval(strMsg)
End Function

Enter this in the immediate window to see how the eval function works here:

?eval ("msgbox(""A@B@C"")")

HTH

John



SurveyorinVA wrote:
>Hello-
>I am currently working in a form which contains a text box that a user will
>use to create a job number and another text box for the job name. Later in
>the same form, the user will have the ability to create certain directories
>based upon this job number and another directory based upon the job name.  I
>would like to put a function behind the after_update event of each event that
>will review this text box and make sure that the string entered does not
>contain any character that would cause a conflict when creating a directory,
>namely the following \ / : ? < > ! characters.  
>
>What would be the best approach to creating this code?
>
>Thank you in advance.
>Chris

-- 
John Goddard
Ottawa, ON Canada
jrgoddard at cyberus dot ca

Message posted via http://www.accessmonster.com

0
J_Goddard
3/17/2008 6:46:10 PM
SurveyorinVA via AccessMonster.com wrote:
>I am currently working in a form which contains a text box that a user will
>use to create a job number and another text box for the job name. Later in
>the same form, the user will have the ability to create certain directories
>based upon this job number and another directory based upon the job name.  I
>would like to put a function behind the after_update event of each event that
>will review this text box and make sure that the string entered does not
>contain any character that would cause a conflict when creating a directory,
>namely the following \ / : ? < > ! characters.  


Typically that kind of thing is done in the control's
BeforeUpdate event, but maybe you're doing more than the
usual.

If Me.textbox Like "*[\/:?<>!]*" Then
	MsgBox "invalid character, try again"
End If

You could also use the text box's ValidationRule property:
	Not Like "*[\/:?<>!]*"
and ValidationText:
	"invalid character, try again"

-- 
Marsh
MVP [MS Access]
0
Marshall
3/17/2008 7:43:50 PM
Thank you all for your quick response.  I appreciate the help and it works
great.
Regards,
CF

Marshall Barton wrote:
>>I am currently working in a form which contains a text box that a user will
>>use to create a job number and another text box for the job name. Later in
>[quoted text clipped - 4 lines]
>>contain any character that would cause a conflict when creating a directory,
>>namely the following \ / : ? < > ! characters.  
>
>Typically that kind of thing is done in the control's
>BeforeUpdate event, but maybe you're doing more than the
>usual.
>
>If Me.textbox Like "*[\/:?<>!]*" Then
>	MsgBox "invalid character, try again"
>End If
>
>You could also use the text box's ValidationRule property:
>	Not Like "*[\/:?<>!]*"
>and ValidationText:
>	"invalid character, try again"
>

-- 
Message posted via http://www.accessmonster.com

0
tobesurveyor
3/17/2008 7:45:12 PM
Reply:

Similar Artilces:

Message Limits
Is there a limit to how many messages Outlook XP can import? If so, is there a way to turn off the limit? Would I be able to import half the messages then import the other half (thus avoiding the message limit)? Is it just an import limit or does Outlook have a general limit on messages it can store? Kol. ----------- "Relax, its only ONES and ZEROS !" What are you trying to import from and what kind of numbers are we talking about here? :-) It might be easier to answer your questions (and give you more precise answers) if there were more specifics to go on. -- Jocelyn Fi...

Max Limit for Values in List Boxes and Combo Boxes in Outlook forms
Folks, a user is setting up a form. She wants to have several combo boxes and list boxes with between 75 and 300 (yes, 300 -- that's not a typo!) possible values in the combo box or list box. Before she starts work on this, she would like to know if there is a limit on the number of possible values for a combo box or a multi-select list box. Is there a limit? Is it defined by the number of characters in the values box, or the number of actual values? What is the limit? Any help here would be appreciated. Thanks. David consulttech2004@hotmail.com ...

Find feature does not work with HTML messages (Content-type: text/html)
I have Outlook 2000 SP-3 running under Windows ME. When using the Find feature to locate all e-mails with a given word in the message, no items are found if the e-mails are of "text/html" content-type. The Find feature appears to work for any messages that have URLs embedded and are "multipart/alternative" or "text/plain" content-type. I noticed a similar post several months ago (see http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=%23qSBYIssDHA.2224%40TK2MSFTNGP09.phx.gbl). Is there a work-around for this problem, or should this be reported t...

Excel should default to autoformat for chart text boxes
Excel in (Office 2003 and as far as I can tell all previous versions of Excel) should default to autoformat for chart text boxes - it currently selects "none" for outline and background options ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.micr...

how do I increase drop list font and box size I created
Font is small and you have to scroll through list due to box size If the dropdown was created using Data Validation.............Font size is set at 8pt Dropdown box height cannot be changed. For workarounds like using a ComboBox and using Zoom see Debra Dalgleish's site on DV Lists. http://www.contextures.on.ca/tiptech.html Gord Dibben MS Excel MVP On Fri, 4 Apr 2008 11:36:02 -0700, cdietz1 <cdietz1@discussions.microsoft.com> wrote: >Font is small and you have to scroll through list due to box size ...

Help with Combo-box
Hey everyone, hopefully someone's run across a problem similar to this and their is a (simple :) solution). Basically I have a simple combo-box that is displayed in a dialog. Now, the problem is that I have around 7200 entries that I want to appear in that box as valid selections...well thus far I haven't been able to get that many entries as a possibility (the combo-box simply refuses to allow me to enter that many fields of data). :( Okay, I tried googling this (thought maybe there was a readily defined maximum on combo-box data size) but I couldn't find anything that wou...

pre-select new record in combo box
Hi, I have a form (frmActivity) with a combo box (cboStore) that gets its data from a table (Store). If there is a new store which dose not show in the combo box I have a command button on the same form that open a popup window for entering the name of the new store. In the 'on close' event of the popup I requeary the combo box (cboStore) on the main form so that the new store will appear. What I would really like is to have the new store already selected in the combo box when the popup is closed. Is this possible and if so how? Thanks, Phil Try after the requery of the ...

Need help extracting text from EDLs
I really am trying to learn this stuff, but I haven't programmed anything since my TRS-80 Basic days and I'm a bit overwhelmed. I want to extract text from Edit Decision Lists so that I have a list of shots used in a film. Here is an example of one event of an EDL: 002 TAPE004 V C 04:45:22:06 04:45:24:14 02:00:08:00 02:00:10:08 FROM CLIP NAME: 7C-4_B_ DLEDL: PATH: /raids/luc_1/bun/reel_02/oscans/1222/bun_7c_4_b_02/2048x1556/ The text that follows "FROM CLIP NAME:" is the name of the clip that I want to extract so that I have a document on onl...

Automatically display set text based on users composition
Hi, im trying to do something really simple, trouble is i dont know what the feature's called to be able to search for tips on how to do it. Basically in outlook messages, when a user begins writing a sentence e.g. "in the terms of" i need a tag to pop up that allows the user to press enter and then the remainder of what they will want to type in will be inserted in, its a yellow tag that comes up above the words. i dont know where it needs to be created and enabled. Cheers, Rhys. ...

Text-To-Columns Fixed Width
When using Text-To-Columns, Excel "recognizes" that the data fits the Fixed Width criteria and PRE-assigns the width. In most of the cases I work with Excel is wrong 99% of the time. Is there a way to force Excel to NOT pre-assign the width (leave everything blank)? On the first panel of the wizard click Delimited, then on the second panel click space as the delimiter. Hope this helps. Pete On Feb 4, 12:50=A0am, TP <T...@discussions.microsoft.com> wrote: > When using Text-To-Columns, Excel "recognizes" that the data fits the Fix= ed > Width ...

Outlook 2003: Cursor automatically in To box when
Whenever I create a new message; reply to one; or forward one in Outlook 2003 on a machine I inherited from someone else at work, the blinking text cursor is automatically placed in the To box. I've never seen this happen before in Outlook or any other email app and its quite annoying. I end up having to either retype the beginning of my message again in the body of the email or cut and paste what i've already began to type. Please help, DMarrs@biziteks.com On Wed, 28 Jul 2004 14:16:12 -0700, <DMarrs@biziteks.com> wrote: >Whenever I create a new message; reply to one...

Moving comment box leader arrow head
Can I move the position of the head of a comment arrow from one corner of the cell it references to another corner? When I display the comment box/arrow for printing it looks as if it is refering to the cell on the right, since the comment arrow points to the upper-right corner of the cell, instead of the upper-left. Francisco ...

Outlook Client on CRM 1.2 Server Box for Demos
Hi, Did a CRM 1.2 install on Windows 2003 Server and all is working well. I have been seeing things on this newsgroup that say I should be able to install the Outlook client as well on this machine although it is an unsupported configuration. This is for demo's only. I am running it under Virtual PC. I would like to not have to have 2 Virtual PC images running just to show the Outlook integration to CRM. When I try to install the Outlook client I get a message at the start saying that the Outlook client is already installed. It is not. Suggestions anyone? Alan ...

Migration Wizard Size Limits?
I'm planning to migrate from 5.5 to 2003 using the Migration Wizard to move my mailboxes. Some of my mailboxes are LARGE (5 GB +). Anyone seen any problems with the Wizard handling mailboxes this large or know of a size limit? ...

Code to send SMS text message?
Hi, I would like to send an SMS text message to a cel phone via code within Excel 2007. Has anyone done this? What code / services / products do I need to accomplish this? Does anyone have an example? Thanks in advance. --Dan What gateway are you using? What you would need to do is to snd a internet message to a gateway provider which would then send the messae out on the wireless land. Most likely you are using a webpage interface from your PC to interface with the gateway. So opening up an internet explorer and goiong to an URL is probably the method to use. ...

Access 2007 Rich Text Question 04-28-07
Hi All In the plan text version of a Memo field you can easily add a date by pressing Ctrl+Colon which makes life easy for the end user. However, if the Memo field is set to the Rich Text Property this no longer works. Or am I missing something? Tom gave me a part answer last week but I cannot see a way of inserting a date on a Rich Text Memo field by using keystrokes Thanks ...

Text box and formatting?
I am working on class schedule and have one text box which spans a few pages. Pages are double columns. I have a header for each class and paragraph given for class description. On the last page, last column, one description appears at the top with empty space for the rest of the column. I would like to change the formatting of the text in the whole text-box so that most of the last column is used. I can select the text in the text box which expands over the few pages and play with the font size, but that would mean that all the text would be the same size. Is there a way that text...

Suddenly not able to save new or open previous files with name lengths over 45 characters
I'm using Excel 2003 if it matters ... I'm wondering if there is a known bug/issue on this. For what ever reason, when I try to save a new file (or for that matter open something done previously) with a name that has more than 45 characters or so (might be off by a couple), I get message that it can't save and then gives me a bunch of reasons (file path might not exist, might have too many characters, folder might be read only, etc). I know file exists in the folder I'm checking - I can email myself the file and open from the email so its definitely there! Any sane insight? ...

Customer Credit Limits
Is there a way to turn off the credit limit warning or give customers an unlimited credit limit. We do not use RMS for AR as that is handled in Great Plains at the home office. -- Doug Langley Dear Doug, the only way you can do so is that either make the credit limit to $99,999,999,999,999.00 or make one database trigger on insert/update of customer info to update automatically his credit limits, the trigger facility give you more control not to worry if you get forget, do u know how to write it if not let me know. Comment me. "DLangley" wrote: > Is there a way to tur...

How do I use text in a cell as a range name in a formula
If cell A1 had the text TEST in it and TEST is the name I have given to a group of cells using the name box what formula can I use to give me the sum of TEST, thats is the sum of the cells in the group called TEST. I understand that I can simply have =SUM(TEST), but I want the formula to refer to Cell A1 to get the name ie =SUM(A1) doesn't work obviously Any help appreciated Thank you In this case, you want to use the INDIRECT function. E.g., =SUM(INDIRECT(A1)) -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Kiwi" &...

Pasting "Character Spacing" adjusted text
Our church office secretary has the Bible on a CD in a Word document. They have used Format>Font>Character Spacing>Position >Raised>by 2.5 rather than "Suberscript" for all the verse numbers. Is there a way to Copy the text and paste it into Publisher to maintain the appearance of the raised verse numbers? I do not see the Character Spacing formatting features in Publisher. We are using Office 2002. Jim wrote: > Our church office secretary has the Bible on a CD in a Word document. > They have used Format>Font>Character Spacing>Position >Raised>...

Filter suddenly limited
I have an excell file that is about 2000 rows. I use the filter t locate rows with same names, The filter now only works thru row 1256. Any suggestions what is causing this -- Neil Hanawal ----------------------------------------------------------------------- Neil Hanawalt's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1589 View this thread: http://www.excelforum.com/showthread.php?threadid=27380 Hi see: http://www.contextures.com/xlautofilter02.html#Limits -- Regards Frank Kabel Frankfurt, Germany Neil Hanawalt wrote: > I have an excell file that is a...

Font Size Problem in Options Dialog Box
I recently noticed that the font size on each of the tabbed dialog boxes under Tools > Options is huge and the words don't even fit in the boxes. The font size of the tab titles in normal. Does anyone know what might cause this, or where it can be reset or adjusted? This condition is recent and has not always been this way. TIA -- Wayne Boatwright o�o ____________________ BIOYA Try starting Outlook one time with the /cleanviews switch. start->run->outlook.exe /cleanviews. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. ...

wrapping text in a query field
I set up the field in table to memo and tried entering a lot of information but when I open the report that field does not expand to show all of the entries. Can this be done in query and reports both. Thanking you in advance. Mary Lou On Dec 12, 12:06 pm, MaryLou <Mary...@discussions.microsoft.com> wrote: > I set up the field in table to memo and tried entering a lot of information > but when I open the report that field does not expand to show all of the > entries. Can this be done in query and reports both. > > Thanking you in advance. > Mary Lou Go to the p...

CSV file with 13space characters in blank cells
In my office we've just received a recurring report which has been modified (by someone. Previously (a CSV file) the Data area (say A1:M30 ) had numbers or blank cells representing 0 (zero) values. Now, however the blank cells ARE NOT BLANK (although they appear blank) all cells without numbers have 13 hard-space values in them, which is causing #VALUE! problems; I temporarily added an intermediate sheet with formula: =IF(ISNUMBER(VALUE(MySheet!B2)),MySheet!B2,0) to eliminate the #Value! problem; Is there a better way? I'm sure there is, just not certain at this point in time. Any ...