.SetFocus from module VBA -
i'm trying set focus in form after update. when within forms class module have no problem. however, need in few forms i'm trying write in module. problem can't .setfocus work unless hardcode form name within class module. whno name of control i'm trying set focus.
i have attempted number of options , none seem work.
here sub. works wonderfully except .setfocus procedure.
sub validatewhno() dim enteredwhno integer dim actform string dim dewhno variant msg integer dim ctrlwhno control enteredwhno = screen.activecontrol.value actform = screen.activeform.name set ctrlwhno = [forms]![frmenterbookdata]![whno] dewhno = dlookup("[whno]", "tbldataentry", "[whno] = " & enteredwhno) if enteredwhno = dewhno msg = msgbox("you have entered " & enteredwhno & " whno. next number " & dmax("[whno]", "tbldataentry") + 1 & ", use this?", 4 + 64, "already used whno!") if msg = 6 screen.activecontrol.value = dmax("[whno]", "tbldataentry") + 1 else screen.activecontrol.value = null ctrlwhno.setfocus 'code wont run end if end if end sub
i've tried number of other methods set focus, such as: forms(actform).whno.setfocus
, forms(actform).controls(whno).setfocus
, screen.activecontrol.setfocus
the current result if no selected in msgbox, value cleared, focus moves next control.
thanks in advanced may offered.
does following make difference?
sub validatewhno(frm access.form) dim enteredwhno integer dim actform string dim dewhno variant msg integer enteredwhno = frm.activecontrol.value actform = frm.name dewhno = dlookup("[whno]", "tbldataentry", "[whno] = " & enteredwhno) if enteredwhno = dewhno msg = msgbox("you have entered " & enteredwhno & " whno. next number " & dmax("[whno]", "tbldataentry") + 1 & ", use this?", 4 + 64, "already used whno!") if msg = 6 frm.activecontrol.value = dmax("[whno]", "tbldataentry") + 1 else frm.activecontrol.value = null frm![whno].setfocus end if end if end sub
and call each form be:
vaidatewhno me
instead of using relative reference form (screen.activeform), code passes form reference through directly , uses reference parent of .setfocus method.
Comments
Post a Comment