473,385 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Very very simple SQL in VB syntax question.

44
Hi folks;
I've only really started to use VB for important stuff quite recently, and SQL is still quite alien to me. I'm finding the syntax a real pain to get the hang of, at the moment it's just a case of shifting the inverted commas around and hoping for the best!

I have an OpenForm operation attached to the On Click property of a button. The WHERE clause generated by Access when you place a command button works fine. Here it is, I'm sure you're all familiar...

stLinkCriteria = "[CustIds]=" & Me![CustomerID]

Now, I want to add something to that clause along the lines of:

stLinkCriteria = "[CustIds]=" & Me![CustomerID] AND [CustomerName] Is Not Null

Its function is pretty straightforward, I don't feel I need to explain it to you lot but I'm having a very difficult time explaining it to Access! I keep getting Type Mismatch and "Access cannot find the field " | "..." errors, as well as plain old Syntax Errors. Can anyone help, or point me in the direction of a good resource?

Thanks!
Mar 24 '09 #1
3 1414
ADezii
8,834 Expert 8TB
@Whizzo
Try:
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[CustIds]= " & Me![CustomerID] & " And [CustomerName] Is Not Null"
Mar 24 '09 #2
ChipR
1,287 Expert 1GB
I can't seem to find a good guide that has everything together. Just remember to put & between every part of the string you are making. You have a string, a variable, and another string so:

Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[CustIds] = " & Me![CustomerID] & " AND [CustomerName] Not Null"
Remember the # around dates. For example:
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[TransactionDate] = #" & txtDateBox & "#"
And remember ' ' around strings. Like:
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[CustomerName] = '" & txtNameBox & "'"
You can also use "" in place of ' like:
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[CustomerName] = """ & txtNameBox & """"
If you aren't using the debugger already, there is any easy way to check and make sure you're doing it right. Once you make the string, right before it's used, do:
Expand|Select|Wrap|Line Numbers
  1. MsgBox stLinkCriteria
That way you can see the resulting string, and know what you messed up if you're getting errors.

Also, + can be used to concatenate strings, but any string + null = null, while any string & null = that string still.
Mar 24 '09 #3
Whizzo
44
Great stuff guys, many thanks! It's a long way from

10 print "I rule!!"
20 goto 10
run

but I'm sure I'll get the hang of it!
Mar 24 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: martin | last post by:
Hello, I just got the SUN Java IDE. (Netbeans IDE 3.5.1) Very very nice, and I worked myself through the tutorial (about making a colorswitch). Now, When I compile it gives no errors at all. So...
2
by: Trimbitas Sorin | last post by:
Hello I have a simple syntax question : What does the following line mean: 1: %checkType; ?? I know that @test="" is an array and $test="" is a simple variable. Thank you With best regards...
3
by: Mike Christie | last post by:
I've got some Java experience but no JSP or ASP and am trying to get to grips with ASP.NET. I'd appreciate some help on a simple question. I have been able to get databinding to work, and can...
2
by: cjl | last post by:
PHPers: I am a total beginner, so please excuse my very simple question. I have been playing with PHP on Windows XP, and mostly using Notepad2 (http://www.flos-freeware.ch/notepad2.html) for...
14
by: dba_222 | last post by:
Dear experts, Again, sorry to bother you again with such a seemingly dumb question, but I'm having some really mysterious results here. ie. Create procedure the_test As
5
by: Hakusa | last post by:
I have the argument items in my class room. class room: def __init__(self, name, description, items*): I thought I remembered from a tutorial I read once, and I've read so many I feel like an...
27
by: Paulo da Silva | last post by:
Hi! I was told in this NG that string is obsolet. I should use str methods. So, how do I join a list of strings delimited by a given char, let's say ','? Old way:
1
by: Oskar Bennet | last post by:
Hi everybody, I am supposed to draw a simple UML diagram for a very small project that consists of less than a dozen classes. I have never been working with UML before, I have read some tutorials...
56
by: mdh | last post by:
As I begin to write more little programs without the help of the exercises, little things pop up that I need to understand more fully. Thus, below, and although this is not the exact code, the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.