473,386 Members | 1,630 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,386 software developers and data experts.

How do I get my strSQL criteria to work in a if then else statement?

Seth Schrock
2,965 Expert 2GB
I'm using SQL in VBA to check if a checkbox is checked or not. I don't get any compilation errors, but when I run the code (On click event for a button), it says "Type mismatch" and doesn't error out on the code side. Here is the code:
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3. strSQL = "SELECT EnableSpecialRate FROM tblCustomers"
  4. strSQL = strSQL & " WHERE CustomerID = Forms!frmACHCallConfirmation!ACHCompanyID;"
  5.  
  6. If strSQL = true Then
  7.      MsgBox "true"
  8. Else
  9.      MsgBox "false"
  10. End If
I checked to make sure that checkbox was formated in the to be true/false instead of yes/no or on/off. If I comment out the If then else statement, it runs okay so obviously there is a problem with my criteria of strSQL = true.

Side note: the msgbox "true" and msgbox "false" will be replaced with other code. I'm just using that for testing purposes so that I know my if then else statement is working.

I'm using Access 2010.
Sep 2 '11 #1

✓ answered by NeoPa

Are you after using DLookup() by any chance? Maybe you want to find the value of tblCustomers.EnableSpecialRate for the record which matches [CustomerID] = Forms!frmACHCallConfirmation!ACHCompanyID?

5 2390
NeoPa
32,556 Expert Mod 16PB
Where to start?

Setting your string to valid SQL is one thing (and it appears you have done that successfully), but that's all you've done. SQL has to be executed in some way if it's to have any meaning as SQL, and this you haven't done. Comparing strSQL = True is functionally equivalent to saying "asdfgh" = True.

When you get around to executing the SQL in the way you want to, you then have a problem in as much as a SELECT SQL string returns a RecordSet. It makes no more sense to check the value of a RecordSet than it does a string.

Perhaps you could try to describe what you're trying to achieve in simple and clear English and maybe we could help you interpret what you're looking for.
Sep 2 '11 #2
NeoPa
32,556 Expert Mod 16PB
Are you after using DLookup() by any chance? Maybe you want to find the value of tblCustomers.EnableSpecialRate for the record which matches [CustomerID] = Forms!frmACHCallConfirmation!ACHCompanyID?
Sep 2 '11 #3
Seth Schrock
2,965 Expert 2GB
You are correct for what I'm trying to do. Looking at what DLookup() does, it looks like the perfect thing and a bunch simpler than what I have already and from the sounds of it, I would need to add even more. Thanks so much.
Sep 2 '11 #4
NeoPa
32,556 Expert Mod 16PB
DLookup() is good for a one-off. The more values you want from the record the more overhead is introduced by DLookup() and the more reason for using Recordset Processing instead. I'll leave that with you as a consideration.
Sep 3 '11 #5
Seth Schrock
2,965 Expert 2GB
Everything worked perfectly. I was even able to use it on my query that counted the number of records. Thanks again and I'll keep in mind what you said for any other problems I come up with.
Sep 3 '11 #6

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

Similar topics

2
by: misscrf | last post by:
I have a search form that is great. I have modified it in such a way, that when search results come up I can bring it back to a useful spot, say an entry form or a report. Here is my lemon (...
6
by: jstaggs39 | last post by:
I want to create a Dcount and an If...Then...Else statement to count the number of records in a table based on the date that is entered to run the form. The If....Else statment comes in because if...
2
by: Arjen | last post by:
Hello, I know there is a way to do a simple if then else statement in the aspx page. Is was something with the ?-sign. Can somebody tell me how the syntax was? Thanks!
3
by: Amy | last post by:
Hi, I have 6 If Then Else statements I was supposed to write. I did so but I know that they have to be wrong because they all look the same. Could someone take a look at them and point me in the...
14
by: Ørjan Langbakk | last post by:
I have a form where the user has the possibility to enclose his name. email, address and phonenumber. I want to be able to check if some of the fields are filled - at least one. This is so that...
2
by: hgwright | last post by:
I have a database where I have fields for First Name and Surname. In the FirstName field we list more than one name. I need to write a statement that will allow me to export this field with only...
8
by: Lebbsy | last post by:
I have two combobox fields with the second combobox (Department) dependent on the first combobox (Ministry). If the value of the first combobox changes the options in the second combobox should...
2
by: MicaK | last post by:
Good Morning, I am new to this forum, and extremely new to VBA, so there may be a very simple explanation to this. I also apologize if I am giving you and excessive amount of detail. I have a...
2
by: rleepac | last post by:
I have a form with a tabbed control on it. I am trying to set certain criteria for some of the tabs to show only when info from other fields meet criteria. Specifically, I have two fields. Both...
6
by: DanicaDear | last post by:
I have this update strSQL that is working great, but I'd like to make it smarter in hopes of preventing input errors. Here is my working code: Else Me.txtScan_Box_Num =...
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.