vba - Is there a way to use an input value (textbox) of a userform as a variable for another userform? -
ok trying accomplish: have 1 userform asks how many new orders user needs process. set user input variable in code (not sure if anything).
private sub commandbutton1_click() userform2.show ordernum.text = neworders 'i changed textbox name ordernum end sub
then when userform2 pops up, want able input more data more specific information orders. if on userform1 entered in 3, want have submit new data userform2 3 different times. tried using - next loop (below) doesn't work. i'm not sure how (or if) can store variables between userforms.
private sub commandbutton1_click() dim lrow long dim ws worksheet set ws = worksheets("core info") ordernum.text = neworders lrow = ws.cells(rows.count, 2).end(xlup).offset(1, 0).row = 1 neworders ws.cells(lrow, 1).value = textbox1.text ws.cells(lrow, 3).value = textbox2.text next userform2.hide end sub
the second userform pops should, nothing works after that. can tell me fix this?
note: realize of above start commandbutton1 (default) on different userforms.
it helpful (and coding practice) give form controls more recognizable names, instead of ambiguous commandbutton1
nomenclature. revise commandbutton1
's name on userform1
form1_submitbutton
. then, use code handle form submission.
sub form1_submitbutton_click() ' textbox control named ordernum on userform1 has captured value 'assign value ordernum textbox named variable in worksheet activeworkbook.names.add "ordernum", me.ordernum.text userform2.show end sub
then, in userform2 change name of command button form2_submitbutton
, use code:
sub form2_submitbutton_click() dim ordernum long ordernum = replace(activeworkbook.names("ordernum").value,"=",vbnullstring) 'the rest of code goes here. end sub
so, have done above create name
in worksheet contains value want use on several forms. can obtain value replace(activeworkbook.names("ordernum").value,"=",vbnullstring)
alternatively, use public variable in code module.
Comments
Post a Comment