1
votes

I am receiving a Run-time error 2176 on a DLookup only when searching executing through a form. (Using Access 2010)

I have supplied my code to be as 'hard coded' as possible to remove the possibility of errors on the form.

Text11.SetFocus My code: Me.Text11.Text = DLookup("[Netherlands]", "Templates", "[Template]= 'SimpleGreeting'")

The weird part: If I run this in the Immediate window it returns the rich text I would like to use

? DLookup("[Netherlands]", "Templates", "[Template]= 'SimpleSuppression'") Some text .... so on and so forth

1
Skip set focus, avoid the .Text property, just use Me.Text11 or if you must have a property, .Value. The .Text propery is only available when a control has focus, but SetFocus can be dodgy, unless you know where you are. - Fionnuala
This worked! Weirdly enough my previous code worked for some but not all data cells in my database - SBruns
Probably because you were somewhere that setfocus was okay. - Fionnuala

1 Answers

0
votes

Skip SetFocus, avoid the .Text property, just use Me.Text11 or if you must have a property, .Value. The .Text propery is only available when a control has focus, but SetFocus can be dodgy, unless you know where you are.