Creating a clear button for the LookupEdit control on Active Forms

The SalesLogix LookupEdit is a screen control that allows you to look up information from a table, capture the record id, and display the friendly name. It is very useful, and widely used.

The one thing that it is missing is the ability to clear out what is in it. i.e. what if you select something and change your mind and need to “un select” it. Oops… sorry – no can do.

I recently needed to enable people to clear things out, and the form had a number of lookups on it, so I took the extra time to turn it into a function. So… here is how you do it.

Step 1 – dim a variable to be global to the form – put this at the top of the code before any other code

dim FormRef

Step 2 – in AXFormOpen, capture a reference to the form.

set FormRef = Sender

Step 3 – on your form, name your button and your lookup edit the same way. So if you have a lookup edit called lueMyLookup, then name your button btnMyLookup. You can create as many of these pairs as you need, as long as you follow the naming convention of starting your lookup name with lue.

Step 4 – in the code behind for the form, insert this subroutine and attach it to the button(s).

Sub btnClearLookupClick(Sender)
dim controlname, i, oCtl
controlname = "lue" & right(Sender.Name, Len(Sender.Name)-3)
For i = 0 to FormRef.ControlCount - 1
If FormRef.Controls(i).Name = controlname then
set oCtl = FormRef.Controls(i)
oCtl.LookupId = ""
oCtl.Text = ""
exit sub
end if
next
End Sub

What this does is to use the button name to figure out what the lookup control is called, and then runs through the list of controls to find it. Once it is found, it then clears the lookupid and text properties.

See, that wasn’t so bad, was it?

ws