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

Running SQL using IF ELSE statement

Hi everyone,

I utterly new to VBA and the goal of my code is to have an IF ELSE statement look into a table in my access DB, find a particular value and then run a SQL query based off of that value. The column can have two different values which is either associated or related. So my logic looks like this:


public function abcd()
IF "column value = related"
DoCmd.RunSQL = "sql statement 1"
ELSE "column value = associated"
DoCmd.RunsSQL = "sql statement 2"

Any help would be much appreciated.

Thanks!
Jan 19 '15 #1
2 1371
jforbes
1,107 Expert 1GB
Sounds like DLookup is what you are looking for:
http://msdn.microsoft.com/en-us/libr...ffice.15).aspx
Jan 19 '15 #2
NeoPa
32,556 Expert Mod 16PB
If you're going to use DLookup(), which certainly makes good sense, then I'd suggest you use Select ... Case instead of If ... Else ... End If as it will then only need to run the DLookup() once.

As DLookup() is processing through a recordset it is not something you want to run any more times than necessary.
Jan 23 '15 #3

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

Similar topics

1
by: windandwaves | last post by:
Hi Folk How do I use the if then else statement in an SQL statement. I tried this: SELECT (IF SSG.ID = SSI.ID then true else false) a, SSG.ID gid, SSG.NAM gnam, SSI.ID iid, SSI.NAM inam,...
7
by: Bob | last post by:
Currently I am using this statement to translate 3 fields in my db thru Visual Basic. I import the data from one table to another then call the IFF statements and the NewDate to translate the...
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...
18
by: swaroophr | last post by:
Which of switch statement and if-else statement takes less time to execute?
2
by: paul | last post by:
Hi all, I've been handed some code and, unless I've got the numbering of parentheses wrong, one of the functions has a curious if-else statement. The thing compiles but is it right? I know the...
2
by: Michaelcis06 | last post by:
I am a student in Trinidad who must learn and use Java as part of the Diploma in Computer Information Systems. I am having some problems in writing a Java Program for a salary and salary deduction. ...
2
by: juan-manuel.behrendt | last post by:
Hello together, I wrote a script for the engineering software abaqus/CAE. It worked well until I implemented a selection in order to variate the variable "lGwU" through an if elif, else...
1
by: Joshua Billings | last post by:
I am working on a programming assignment, and I can't figure out what is wrong with these lines of code. if ad > 6: rectAD.setFill("red") if ad <= 3: rectAD.setFill("red") else: ...
5
Seth Schrock
by: Seth Schrock | last post by:
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...
4
by: tastingoo | last post by:
Hi, I'm having problems accessing the worksheet after creating the worksheet in an IF statement. For some reason, if I create the worksheet in the else statement, my $rxsheet address is gone...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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:
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
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,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.