Run Query Based on IF Statement

cstickman

Registered User.
Local time
Today, 07:26
Joined
Nov 10, 2014
Messages
109
Hey everyone,

So I was working on a project and I have two queries, but I only want one or the other to run based on a dlookup with another table.

So my codes does three IF statements in the beginning. It checks to see if the data has already been inputted. Then it will transfer an excel spreadsheet into a temp table. Once that is complete I have 7 queries that will run in the background on the temp table to format it and move stuff around. So what I want is the third query down either needs to put data in three columns or if information is already in those three columns then put it in another three columns. So I was thinking of something like this for the code:

<code>
If IsNull(DLookup("[createdtime]", _
"table1", _
"[createdtime]=" ")) Then
DoCmd.OpenQuery "qry1"
Else
If IsNull(DLookup("[createdtime]", _
"table1"
"[createdtime]=" ")) = False Then
DoCmd.OpenQuery "qry2"
End If
End If

A is this the correct way or am I missing something? Thanks
 
Your evaluation for the dlookup is not correct - the second one should be
Code:
If [COLOR="Red"]Not[/COLOR] IsNull(DLookup("[createdtime]", "table1","[createdtime]=[COLOR="Red"]' '" [/COLOR])) Then
DoCmd.OpenQuery "qry2"
You need to Remove the false, and change the string test as per above. Are you trying to test for a space , null string or empty string ?

It would probably be more elegant to build the correct update query in SQL and then run it using currentdb.execute but that's being a little picky...
 

Users who are viewing this thread

Back
Top Bottom