|
-
Aug 11th, 2005, 03:48 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Yet another SQL issue
Hi guys,
I'm having difficulty in getting text from a textbox on a form. What I'm trying to do is use a textbox for completing an SQL statement.
For example, say the textbox name is txtMonth. I have a String variable called insert
VB Code:
Dim insert as String
insert = txtMonth.txt
sqlStmt = "INSERT INTO <Tablename> VALUES ('" & insert "');"
There are no syntax errors or errors of any kind in the SQL statment, so it must be a problem getting the text from the textbox.
Any suggestions?
Thanks
Last edited by MethadoneBoy; Aug 17th, 2005 at 04:16 AM.
Reason: Resolved
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
-
Aug 11th, 2005, 04:43 AM
#2
Re: Yet another SQL issue
What Applicaiton is this being performed on? Which Control? and Which Event?
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Aug 11th, 2005, 04:48 AM
#3
Re: Yet another SQL issue
Try...
VB Code:
Dim insert1 as String
insert1 = txtMonth.txt
sqlStmt = "INSERT INTO Tablename VALUES('" & insert1 "');"
-
Aug 11th, 2005, 05:20 AM
#4
Thread Starter
Addicted Member
Re: Yet another SQL issue
 Originally Posted by dannymking
What Applicaiton is this being performed on? Which Control? and Which Event?
It's being written as part of an Access Form. The code is called when a button (CmdDoit) is clicked.
 Originally Posted by dee-u
Try...
VB Code:
Dim insert1 as String
insert1 = txtMonth.txt
sqlStmt = "INSERT INTO Tablename VALUES('" & insert1 "');"
Tried that and still no success. Thanks for the help, though.
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
-
Aug 11th, 2005, 05:50 AM
#5
Re: Yet another SQL issue
Silly question but are you executing the sql statement on a command object??
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Aug 11th, 2005, 07:27 AM
#6
Re: Yet another SQL issue
My point exactly.. which is why the initial questions..
You cannot reference the text value of an control without setting the focus first.. the default is value.. I'm surprised it's not throwing an error about the set focus..
So the code should be
VB Code:
Dim insert1 as String
insert1 = txtMonth
sqlStmt = "INSERT INTO Tablename VALUES('" & insert1 "');"
I presume there is more code following this to actually execute the query..
Try that and post back if still not resolved
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Aug 11th, 2005, 07:38 AM
#7
Re: Yet another SQL issue
Sorry danny, but that has got to be one of the lamest things I have ever heard.... 1) IT is possible to get the text value of a control w/o setting focus... 2) While it's not necessary to use .Text... it's a good idea. Lastly, no one said anything about set focus errors. Where did that come from?
Methadone - A couple of questions and a comment for you:
Comment first: What you have done in your first post is akin to saying "Doc I hurt. It must be my appendix, because my leg bleeds just fine." You've said there's a problem and you've seemed to diagnosed it yourself, yet you never said what the symptoms are.
HOW do you know there's a problem getting the text? Do you get an error? Does the update even happen? HOW are you executing the query? Have you done a msgbox on insert and sqlStmt? What are their values? What does sqlStmt look like after putting it all together (but before executing)?
Tg
-
Aug 11th, 2005, 07:57 AM
#8
Re: Yet another SQL issue
 Originally Posted by Techgnome
1) IT is possible to get the text value of a control w/o setting focus...
In an Access Database it is not possible...
A simple MsgBox from a command button that returns the Text property of a Textbox in an Access Form returns the following error message...
Run-Time error '2185'
You can't reference a property or method for a control unless the control has the focus.
and I quote
 Originally Posted by Methadoneboy
It's being written as part of an Access Form. The code is called when a button (CmdDoit) is clicked.
The value propery of a control on an Access Form can be referred to without setting the focus to the control... 
 Originally Posted by techgnome
Lastly, no one said anything about set focus errors. Where did that come from?
I said
 Originally Posted by dannymking
I'm surprised it's not throwing an error about the set focus..
Remember This is Access and not VB..
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Aug 11th, 2005, 08:36 AM
#9
Re: Yet another SQL issue
Beg to differ
Quote:
Originally Posted by Techgnome
1) IT is possible to get the text value of a control w/o setting focus...
In an Access Database it is not possible...
Do not use the .text with access forms. no need for the focus.

It will only not work if you are in the text box and fire a before update on it, because the value is not set yet. But then the .text works and you have the focus... so if wouldn't make the error you posted. Uh well. Try n see?
Last edited by Ecniv; Aug 11th, 2005 at 09:09 AM.
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Aug 11th, 2005, 08:54 AM
#10
Re: Yet another SQL issue
Well I'll be.... Humble pie, one please, a la mode if possible.... it's still the lamest thing I've ever heard of (well, actualy it makes the top 10, a former co-worker will always retain spots 1-5 at least, but that's another matter)... then again, MS isn't not exactly the poster child of consistancy.
Still, shouldn't this have thrown an error (focus or not) -- insert = txtMonth.txt
.txt????
Tg
-
Aug 11th, 2005, 09:03 AM
#11
Re: Yet another SQL issue
I'll give you that one.. didn't spot the .txt thing.
A Compile error will be returned stating "Method Or Data member not found".. Adding the e in will return Runtime Error '2185' taking the .txt out will result in a (hopefully) working command button click...
Why is it still lame...
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Aug 11th, 2005, 10:47 AM
#12
Re: Yet another SQL issue
Because that makes .Text inconsistant with VB.... but I guess Access has always done it's own thing...
Tg
-
Aug 11th, 2005, 10:56 AM
#13
-
Aug 17th, 2005, 04:15 AM
#14
Thread Starter
Addicted Member
Re: Yet another SQL issue
 Originally Posted by techgnome
What you have done in your first post is akin to saying "Doc I hurt. It must be my appendix, because my leg bleeds just fine." You've said there's a problem and you've seemed to diagnosed it yourself, yet you never said what the symptoms are.
Noted.
 Originally Posted by techgnome
HOW do you know there's a problem getting the text? Do you get an error? Does the update even happen? HOW are you executing the query? Have you done a msgbox on insert and sqlStmt? What are their values? What does sqlStmt look like after putting it all together (but before executing)?
I've managed to resolve the issue since I posted this query. Well, I didn't resolve it, truth be told, just found a way around it.
TO answer your questions, I initially thought there was a problem getting the text because, I would first of all enter the text (I did actually set the focus to the textbox) then click a command button which would feed that text into the sql String, which would in turn extract data from a table. No data was being received. I added another textbox to the form to see if text was being assinged to the "insert" variable - it was. So there must be something wrong with the sql String. For some reason it wasn't extracting data.
I managed to solve this part of the problem by breaking the String into smaller parts as opposed to one long statement eg:
sqlStr = "SELECT <col1>, <col2>, "
sqlStr = sqlStr & "<col3>, <col4>, "
..... you get the idea.
This solved the problem I had encountered, but I'm not sure why. If anyone could explain why one long String of an sql Statement wouldn't work as opposed to a String built up, I'd appreciate it.
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
-
Aug 17th, 2005, 04:21 AM
#15
Re: [RESOLVED] Yet another SQL issue
I wouldnt find any difference with a long sql statement with a breaked one, I usually just put in one line all my sql statements and encountering no problem with it, if you could post that long sql statement of yours then maybe we could check for any syntax errors...
-
Aug 17th, 2005, 04:22 AM
#16
Re: [RESOLVED] Yet another SQL issue
An Access query string can be upto 64,000 characters long.. It would be better to see what your actual sql string was, as things like spaces in field names need to be surounded by square brakets...
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Aug 17th, 2005, 04:34 AM
#17
Thread Starter
Addicted Member
Re: [RESOLVED] Yet another SQL issue
 Originally Posted by dannymking
An Access query string can be upto 64,000 characters long.. It would be better to see what your actual sql string was, as things like spaces in field names need to be surounded by square brakets...
I don't think there were any syntax errors as once I split the String down, it worked fine - I hadn't made any fundamental changes to the text. I had field names enclosed in square brackets and everything seemed in order.
I'm a little hesitant about posting the names of the tables and fields here as they're work-sensitive. I just wanted to see if anyone knew offhand why a long String would fail and a component String wouldn't.
Thanks to everyone who helped, though!
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|