loading a variable depending on what form just closed

Chrisopia

Registered User.
Local time
Today, 09:59
Joined
Jul 18, 2008
Messages
279
I am creating a step by step wizard, which means transferring variables to another form,

Dim ID As String
ID = me.Id
Open form
form.Id = ID
Close original form

one issue I have is if the wizard takes a step back...
I need a snippet of code to tell the form where to get the variable from.

Here's what I have (that doesn't work) -
Private Sub Form_Load()

If (fIsLoaded(Step1b) = True) Then
AddID = Forms!Step1b!AddressList.Column(2)
Else
AddID = Forms![Customer Contact Details]!AddID
End If

End Sub

What this is supposed to do is check if Step1b is loaded then take the Address ID from there, if it's not then it's to assume "Customer Contact Details" is open, and instead take the address ID from there. But no avail.

fIsLoaded is a function I found which checks if the form is open or not,
Function fIsLoaded(ByVal strFormName As String) As Integer
'Returns a 0 if form is not open or a -1 if Open
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0 Then
If Forms(strFormName).CurrentView <> 0 Then
fIsLoaded = True
End If
End If
End Function

However it's run in the onLoad event, which annoyingly runs after the old form has closed, so always returns false!

Any help will be appreciated... even if I'm doing this wrong, and I should restructure my wizard differently?
 
One thing you can do is to put your function 'fIsLoaded' in a module as a Public Function so it remains in scope for every form.

Does your wizard sit in its own form or module? If so, you could use a dynamic array to keep track of previous steps.
Code:
Dim ID As String
Dim strForms() As String
Rem force a single element in the array
ReDim strForms(0)
ID = Me.ID
Rem put the id in the highest array slot
strForms(UBound(strForms)) = ID
Rem add another slot ready for the next form name
ReDim Preserve strForms(UBound(strForms) + 1)
Rem Open form
Form.ID = ID
Rem Close original form
Clearly the logic here is not correct, but it shows the principles you need. The process of building the array needs to be in a loop.
The initial Redim is there to allow the first UBound statement to work. If you use an index, you can control the array size from that and simply Redim whenever you need to add a new element.
If you have to go back one or more forms, you iterate the array in reverse order, or just pick off the penultimate element if the one you want is always in that position in the array.
Code:
Rem retrieve the penultimate form name from the array
strPreviousFormName = strForms(UBound(strForms) - 1)
 

Users who are viewing this thread

Back
Top Bottom