Results 1 to 3 of 3
  1. #1
    opopanax666 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2010
    Posts
    27

    How to turn the format of a textbox back to text?

    Silly question, really, but did not find a single example of exactly how to do this. How to change a textbox to handle numbers & dates no problem, but how to change it back to text: not one explicit example!

    So, here's the problem:



    I have a form (not bound) with a 5-option group and 2 textboxes (not bound). If one of the first three options is picked, nothing should change, and the user should be able to input text. When one of the last two options is picked, then the user should be able to pick a date.

    Code in the AfterUpdate:
    Code:
    Select Case Me.optgrpZoeken.Value
    
        Case 1
            Me.txtZoeken1.Format = "text"
            Me.txtZoeken1.Enabled = True
            Me.txtZoeken2.Format = "text"
            Me.txtZoeken2.Enabled = False
            
        Case 2
            Me.txtZoeken1.Format = "text"
            Me.txtZoeken1.Enabled = True
            Me.txtZoeken2.Format = "text"
            Me.txtZoeken2.Enabled = False
        
        Case 3
            Me.txtZoeken1.Format = "text"
            Me.txtZoeken1.Enabled = True
            Me.txtZoeken2.Format = "text"
            Me.txtZoeken2.Enabled = False
        
        Case 4
            Me.txtZoeken1.Format = "short date"
            Me.txtZoeken1.Enabled = True
            Me.txtZoeken2.Format = "short date"
            Me.txtZoeken2.Enabled = True
        
        Case 5
            Me.txtZoeken1.Format = "short date"
            Me.txtZoeken1.Enabled = True
            Me.txtZoeken2.Format = "short date"
            Me.txtZoeken2.Enabled = True
    
    End Select
    The reason I want to put the format to text is that when a user picks one of the last two, but changes his/her mind, the textbox changes back to text instead of the date-picker.

    Problem now is that when I open the form (default = 1), the textbox is "text" (clicking in the box: cursor on the left). I then pick option 2 (should still be text), click inside the box and see the cursor on the right When I try to type text, the damn thing gives me an error, saying that I'm trying to type text in a number field Nowhere did I change the properties of the textbox to a number, not through VBA, not through control properties, and also means that the syntax of the format = "text" is probably wrong. So I'm a bit at a loss as to why this would/could even happen...

    Anybody any clue?

    TIA,
    James
    Last edited by opopanax666; 11-29-2012 at 08:33 AM. Reason: solved

  2. #2
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    You're correct: there's no such format as "text." You may get some weird masking effects from your code. Instead try

    Me.txtZoeken1.Format = ""

    PS Personally I would put the code in the Before Update of the option box since I don't know if you can change the format of a control that has the focus.
    Last edited by Rod; 11-29-2012 at 08:04 AM. Reason: Added PS

  3. #3
    opopanax666 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2010
    Posts
    27
    Quote Originally Posted by Rod View Post
    You're correct: there's no such format as "text." You may get some weird masking effects from your code. Instead try

    Me.txtZoeken1.Format = ""

    PS Personally I would put the code in the Before Update of the option box since I don't know if you can change the format of a control that has the focus.
    The Format = "" did the trick, and leaving it in the AfterUpdate worked as intended (in fact, changing it to BeforeUpdate gave errors ).

    Thank you very much for the tip,
    James

Please reply to this thread with any new information or opinions.

Similar Threads

  1. turn "about to delete record" warning back on
    By markjkubicki in forum Programming
    Replies: 1
    Last Post: 11-01-2012, 12:21 PM
  2. Replies: 4
    Last Post: 05-21-2012, 08:21 AM
  3. SET focus back to TEXTBOX if validation does NOT pass
    By taimysho0 in forum Programming
    Replies: 5
    Last Post: 12-04-2011, 10:10 PM
  4. On click textbox inserts value back on combobox
    By whitelockben in forum Forms
    Replies: 2
    Last Post: 10-09-2011, 05:23 AM
  5. Replies: 8
    Last Post: 05-26-2011, 09:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums