Results 1 to 4 of 4

Thread: [RESOLVED] Set text boxes blank in an access form

  1. #1

    Thread Starter
    Hyperactive Member r0k3t's Avatar
    Join Date
    Dec 2005
    Location
    Cleveland
    Posts
    361

    Resolved [RESOLVED] Set text boxes blank in an access form

    Hi there,

    I have the following code.

    Code:
      strSQL = "Insert Into tblTicker(CompanyName,Ticker,Exchange,Exchange1,Exchange2)"
        strSQL = strSQL & " Values ('" & Me.CompanyName & "', '"
        strSQL = strSQL & Me.Ticker & "','" & Me.Ex1Text & "','" & Me.Ex2Text & "','" & Me.Ex3Text & "')"
        DoCmd.RunSQL strSQL
        
       
        
        MsgBox "New company has been added"
        Me.CompanyName = ""
        Me.Ticker = ""
        Me.Ex1Text = ""
        Me.Ex2Text = ""
        Me.Ex3Text = ""
    You can clearly see what I am trying to do. I insert the data (which works fine) then I want to clear out the textboxes however I get an error - it says...



    What I don't understand is how is it somehow associated with that row now? I come from a C# / Web background and so I don't really understand this so well... If someone can point me in the right direction that would be swell!

    Thanks!
    Anti DUPLO machine!!!

  2. #2
    New Member
    Join Date
    Apr 2009
    Posts
    13

    Re: Set text boxes blank in an access form

    I'm not an Access expert by any means, but by looking at the error message it seems like there's some data validation rule for the table that the text box is bound to that prevents blank strings, and to Access text box contents = table field contents.

    I'd hazard a guess that you need to go down one of these roads:
    1. Change the data validation rule for the table
    2. Unbind the text box from the table field and use code to populate the field based on the box contents
    3. Set the box equal to " " (space) rather than "" (null string) so that it looks empty, but isn't

  3. #3
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Set text boxes blank in an access form

    For Text fields, there is an option AllowZeroLength value, you can set that to True/False.
    If that is False, you cannot set its value to "" but you have to set it to Null.
    In your case:
    Code:
        Me.CompanyName = Null
        ...
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  4. #4

    Thread Starter
    Hyperactive Member r0k3t's Avatar
    Join Date
    Dec 2005
    Location
    Cleveland
    Posts
    361

    Re: Set text boxes blank in an access form

    Hi there

    Lamprey had it right - It was the "Control Source" property - once I cleared that out I was all set...

    Thanks!
    Anti DUPLO machine!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width