[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...
http://www.refreshless.net/images/accessError.jpg
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!
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
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
...
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!