Textbox to perform dlookup if checkbox is checked, show text from another box if not (1 Viewer)

mattscott

New member
Local time
Today, 23:23
Joined
Sep 9, 2013
Messages
9
Hi people,

Working with very limited Access knowledge from years ago combined with a lot of googling.

I have a text box on a form, currently it performs a dlookup for me. I want to change it so that it only performs the Dlookup if a checkbox is checked, but otherwise will display the text that's in an unbound text box.

Not 100% this is even possible, but hoping so. So far I have in the textbook:

=IIf([CHECKBOX]=0,DLookUp("TABLE","FIELD","ID = " & [Text57] & ""),[TEXTBOX])

The dlookup works fine by itself, it's just making it conditional that's causing me problems. I know it could just be a small problem with the way I've written it, or it could be a bigger thing with me not understanding the way IIF works.

Any help appreciated, thanks :)
 

mattscott

New member
Local time
Today, 23:23
Joined
Sep 9, 2013
Messages
9
One other potential solution to this would be if it's possible for the dlookup to be performed in TEXTBOX if the box is checked, but if not checked let me manually enter text in that same box. This seemed less possible when I looked into it but I'd be happily proven wrong.
 

bob fitz

AWF VIP
Local time
Today, 23:23
Joined
May 23, 2011
Messages
4,719
In your post you said you had:
=IIf([CHECKBOX]=0,DLookUp("TABLE","FIELD","ID = " & [Text57] & ""),[TEXTBOX])
The first argument of DLookup() should be a field name and the second should be the name of a table or a query. So perhaps you need:
=IIf([CHECKBOX]=0,DLookUp("FIELD","TABLE","ID = " & [Text57] & ""),[TEXTBOX])
 

mattscott

New member
Local time
Today, 23:23
Joined
Sep 9, 2013
Messages
9
In your post you said you had:
=IIf([CHECKBOX]=0,DLookUp("TABLE","FIELD","ID = " & [Text57] & ""),[TEXTBOX])
The first argument of DLookup() should be a field name and the second should be the name of a table or a query. So perhaps you need:
=IIf([CHECKBOX]=0,DLookUp("FIELD","TABLE","ID = " & [Text57] & ""),[TEXTBOX])

Good spot, afraid that was just me mislabelling things when making the post, it's correct in the actual formula itself.

Problem solved anyhow I think! Just needed to use a toggle button instead of a check box. I guess check boxes just don't quite work that way. Thanks guys.
 

Users who are viewing this thread

Top Bottom