dlookup hangs(not reponding)

  • Thread starter Thread starter adriany
  • Start date Start date
A

adriany

every time i enter wrong # to txtbox1, program hangs (not
responding error)for 30 sec to long, any way to shorten
this problem.

txtbox1 have after update [Event Procedure] to Dlookup

txtbox2 = DLookup("fld1", "query1", "fld2= '" & fld2
& "'")

any good way to solve this problem?


thanks in advance
adriany
 
Hi,


It would be preferable to use a SQL statement rather than a saved query
since a saved query has no INDEX.

On Error Resume Next

txtbox2=CurrentDb.OpenRecordset("SELECT fld1 FROM ... WHERE fl2='" &
fl2 & """" , dbOpenForwardOnly, dbReadOnly ).Fields(0).Value

If 0 <> Err.Number then
'... can test the error number, or "assume" the error is about
no record is returned
' in the previous OpenRecordset statement

txtbox2=vbNullString
End if

Err.Clear


Using a SQL statement, you can also add an index on fl2 field of the implied
table. ForwardOnly+ReadOnly recordset are generally among the fastest (low
overhead) recordsets we can have.


Hoping it may help,
Vanderghast, Access MVP
 
Back
Top