PDA

View Full Version : [VBA-excel 2007] How to check if variable exist on userform



vocedicore
02-13-2019, 09:02 PM
Hi All,

I have 2 different userform as origin and 1 userform as destination, 1 module to manipulate data sending.
it need to be copy variables to destination userform variables.
But if variables not exist in destination userform, variables will not proceed to copy.
1) Please advise how to check if variable is exist on destination userform.
2) How to copy those group of variable dealing with for each in loop?

I appreciate it in advance.


for each obj in variables in frmDest
obj = frmOrgA.obj 'if variable exist, the variables name is same
next obj

frmOrgA(Userform): 3 variable (strA as string, strB as string, strC as string)
frmOrgB(Userform): 4 variable (strA as string, strB as string, strC as string)
frmDest(Userform): 3 variable (strA as string, strB as string, strC as string)

------frmOrgB(Userform)----------

Public Sub cmdDest_Click()
Set Tg = frmDest
Call IncomingSync(Me, Tg)
End Sub

------Global(Module)-----------

Public Sub IncomingSync(OrgUF As Object, TgUF As Object)
ICrun = False: ICrun = True
TgUF.strA = OrgUF.strA ' can be use for each in?
TgUF.strB = OrgUF.strB
TgUF.strC = OrgUF.strC
If not TgUF.strD is nothing Then TgUF.strD = OrgUF.strD 'can I detect if variable is exist?
frmDest.Show
End Sub

Aflatoon
02-14-2019, 04:16 AM
There are several ways to approach this. You could use one array of values in each form and simply loop through it; you could implement interfaces that you can check and react accordingly; you could use CallByName (and ideally implement properties for the forms).

vocedicore
02-14-2019, 11:45 AM
This is hard to make it for me, Could you show sample of code?




There are several ways to approach this. You could use one array of values in each form and simply loop through it; you could implement interfaces that you can check and react accordingly; you could use CallByName (and ideally implement properties for the forms).