How do I run the same expression for different variables?

A

AMN

Hi,

I have an expression with two variables that I would like to run multiple
times (10 times) to result in 10 different strings. Here is some details:

'Variable "stX" is a string and "Y" is a field in a different table.
I would like to run the following expression:

Private Sub UpdateMemo_Click ()
Dim stHeader as string
stX = DLookUp ([Y], "Table", MRN = Me.MRN)
If Not stX = "" Then
stX = VbNewLine & stX
stHeader = "List:"
Else
stX = " "
End If

If Not stHeader = "" Then
Me.Memo = stHeader & st1 & st2 & ... & st10
End If
End Sub

How do I do this? Your help is very much appreciated.

Thanks,
 
D

Damian S

Hi AMN,

Write your expression as a function that takes two parameters and returns a
string.

eg:

public function something(stX as string, Y as integer) as string
<calculations go here>

' return the value
something = <value to return>
end function

Hope this helps.

Damian.
 
A

AMN

Hi Damian,

Thank you. I am a novice and hence a little confused. I have never worked
with a function. Is my calculation the script that I had written
originallly? And if so, when you say something = <value to return>, is that
where you define what stX and Y are (e.g. something = (st1, field1))?

Sorry about the confusion.



Damian S said:
Hi AMN,

Write your expression as a function that takes two parameters and returns a
string.

eg:

public function something(stX as string, Y as integer) as string
<calculations go here>

' return the value
something = <value to return>
end function

Hope this helps.

Damian.

AMN said:
Hi,

I have an expression with two variables that I would like to run multiple
times (10 times) to result in 10 different strings. Here is some details:

'Variable "stX" is a string and "Y" is a field in a different table.
I would like to run the following expression:

Private Sub UpdateMemo_Click ()
Dim stHeader as string
stX = DLookUp ([Y], "Table", MRN = Me.MRN)
If Not stX = "" Then
stX = VbNewLine & stX
stHeader = "List:"
Else
stX = " "
End If

If Not stHeader = "" Then
Me.Memo = stHeader & st1 & st2 & ... & st10
End If
End Sub

How do I do this? Your help is very much appreciated.

Thanks,
 
A

AMN

Thank you,

I think I got it.



Damian S said:
Hi AMN,

Write your expression as a function that takes two parameters and returns a
string.

eg:

public function something(stX as string, Y as integer) as string
<calculations go here>

' return the value
something = <value to return>
end function

Hope this helps.

Damian.

AMN said:
Hi,

I have an expression with two variables that I would like to run multiple
times (10 times) to result in 10 different strings. Here is some details:

'Variable "stX" is a string and "Y" is a field in a different table.
I would like to run the following expression:

Private Sub UpdateMemo_Click ()
Dim stHeader as string
stX = DLookUp ([Y], "Table", MRN = Me.MRN)
If Not stX = "" Then
stX = VbNewLine & stX
stHeader = "List:"
Else
stX = " "
End If

If Not stHeader = "" Then
Me.Memo = stHeader & st1 & st2 & ... & st10
End If
End Sub

How do I do this? Your help is very much appreciated.

Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top