VBA based on DLookup query, and use DLookup result to open form (1 Viewer)

TB11

Member
Local time
Today, 09:00
Joined
Jul 7, 2020
Messages
78
Hi. I'm trying to open a form based on a DLookup value from a query. The results from the DLlookup will be either a 1 or 0. I would like to open the form only if the DLookup = 1

I'm struck on the where condition.

Private Sub OpenUnbilled_Click()

Dim tmp As String

tmp = DLookUp("IsUnbilled", "q_StartEndDate", "IdMatter=" & Forms!f_Start_End_Date!cbo_Matter)

DoCmd.OpenForm FormName:="f_StartEndDate_Unbilled"
WhereCondition:=

End Sub
 

plog

Banishment Pending
Local time
Today, 09:00
Joined
May 11, 2011
Messages
11,611
First, Dlookup isn't guaranteed to return a 1 or 0 or anything--it can return a NULL if the criteria isn't met. Then DoCmd.OpenForm allows you to pass a filter with the call:


That will also show you how to pass the form name correctly.
 

Gasman

Enthusiastic Amateur
Local time
Today, 14:00
Joined
Sep 21, 2011
Messages
14,042
You also pass it's value to a string variable.?
I am guessing that Unbilled is a Boolean field?, so I would check for True ?

As you are looking for that value from "IdMatter=" & Forms!f_Start_End_Date!cbo_Matter, then I suspect that would also be your where condition?
 

Users who are viewing this thread

Top Bottom