|
-
Feb 9th, 2005, 03:53 PM
#1
Thread Starter
Frenzied Member
SQL beginner question... [Solved]
Can you insert SQL code directly into a Access Module and if so can someone provide me with a example statement to update a blank field with a variable?
Thanks for any help I am pulling my hair out. :P
Last edited by Besoup; Feb 10th, 2005 at 08:52 AM.
Reason: solved
-
Feb 9th, 2005, 04:14 PM
#2
Thread Starter
Frenzied Member
Re: SQL beginner question...
VB Code:
Dim dbsCurrent As Database
Dim qryTest As QueryDef
Set dbsCurrent = CurrentDb
Set qryTest = dbsCurrent.QueryDefs("UpdateQuery")
qryTest.SQL = "UPDATE [TestTable] SET [TestTable].[Field1] = "test"
WHERE ((([TestTable].[Field1])=""));"
This is pretty much what I want to do but I would like to replace the "test" with a variable if that is at all possible. Can anyone help out with this? Thanks in advance
-
Feb 9th, 2005, 04:42 PM
#3
Fanatic Member
Re: SQL beginner question...
You'll have to set your variable somewhere, through user input or however you're filling it, then try this...
VB Code:
"UPDATE [TestTable] SET [TestTable].[Field1] = '" & test & "' WHERE ((([TestTable].[Field1])=""));"
Note - you don't need the single quotes before and after the variable if the variable is numeric, only need them for text.
Here's to us!
Who's like us?
Darned few, and they're all dead!
-
Feb 9th, 2005, 04:51 PM
#4
Thread Starter
Frenzied Member
Re: SQL beginner question...
VB Code:
Dim dbsCurrent As Database
Dim qryTest As QueryDef
Dim stTest as string
stTest = "what I want"
Set dbsCurrent = CurrentDb
Set qryTest = dbsCurrent.QueryDefs("UpdateQuery")
qryTest.SQL = "UPDATE [TestTable] SET [TestTable].[Field1] = " & stTest & _ "WHERE ((([TestTable].[Field1])=""));"
Tried this with the single quotes and without and I keep getting a syntax error.... beginning to think its impossible =/
-
Feb 9th, 2005, 05:06 PM
#5
Fanatic Member
Re: SQL beginner question...
VB Code:
qryTest.SQL = "UPDATE [TestTable] SET [TestTable].[Field1] = '" & stTest & "' WHERE ((([TestTable].[Field1]) Is Null));"
Keep it all on the same line, your line continuation is throwing it off, and remove the quotes where you're looking for the empty field, us is null instead.
Here's to us!
Who's like us?
Darned few, and they're all dead!
-
Feb 9th, 2005, 06:37 PM
#6
Thread Starter
Frenzied Member
Re: SQL beginner question...
Will try that when I get to work in the morning... gawd I hope it works. Thanks for the help
-
Feb 10th, 2005, 08:51 AM
#7
Thread Starter
Frenzied Member
Re: SQL beginner question...
 Originally Posted by demotivater
VB Code:
qryTest.SQL = "UPDATE [TestTable] SET [TestTable].[Field1] = '" & stTest & "' WHERE ((([TestTable].[Field1]) Is Null));"
Keep it all on the same line, your line continuation is throwing it off, and remove the quotes where you're looking for the empty field, us is null instead.
Thanks alot man got it running was a big help.
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
|