Need help in Function that combines two values and return a single value

F

FA

I need a VBA function that takes two values

Dim Val1 As String
Dim Val2 As Date
Dim Val3 As String

Combine Val1Val2 and return a single value Val3 As String

With Val3 Add 001 for the first record 002 for the second record and so
on

insert Val3001 into a texbox

So for Example if Val1 = ABCDE, Val2 = 01/01/2006
Val3 shoule be = ABCDE01/01/2006001 --- for the first recode (or for
the first time)

Can someone help me please?

Thanks Bunch


Moe
 
S

Stefan Hoffmann

hi,
I need a VBA function that takes two values
Combine Val1Val2 and return a single value Val3 As String
Public Function Foo(Val1 As String, Val2 As Date, RecNo As Long) As String
Foo = Val1 & Val2 & RecNo
End Function

placed in a normal module should do it.
So for Example if Val1 = ABCDE, Val2 = 01/01/2006
Val3 shoule be = ABCDE01/01/2006001 --- for the first recode (or for
the first time)
It just needs some formatting.


mfG
--> stefan <--
 
F

FA

Thanks stefan, i created a new module,
Public Function CalculateFindingNo(Val1 As String, Val2 As Date, RecNo
As Long) As String
CalculateFindingNo = Val1 & Val2 & RecNo
End Function

I have it exactly like this but when i enter two variables Val1 and
Vale2 in the immediate window, it does not return the third value with
both Val1 and Val2 combined having 001 next to it.

I need to place this funtion on a little form that has three text
boxes, the value of textbox1 would be Val1 and the value of textbox2
would be Val2. there is a command button and i believe i have to call
this funtion in the onclick even of this command
button to to see the result in textbox3.

Please help me

Thanks

Moe
 
F

FA

i tried the following code also and tried to test it in the immediate
window by typing

abcde, 01/01/2006
its giving me

compile error:
Sub or Funtion not defined

Public Function CalcFindingNo(Val1 As String, Val2 As Date) As String

CalcFindingNo = Val1 & Val2

End Function
 
S

Stefan Hoffmann

hi,
Public Function CalculateFindingNo(Val1 As String, Val2 As Date, RecNo
As Long) As String
CalculateFindingNo = Val1 & Val2 & RecNo
End Function

I have it exactly like this but when i enter two variables Val1 and
Vale2 in the immediate window, it does not return the third value with
both Val1 and Val2 combined having 001 next to it.
Use

? CalculateFindingNo("Val1", Date(), 1)

in the immediate window.
I need to place this funtion on a little form that has three text
boxes, the value of textbox1 would be Val1 and the value of textbox2
would be Val2. there is a command button and i believe i have to call
this funtion in the onclick even of this command
button to to see the result in textbox3.
In the on click event of your button:

textbox2.Value = CalculateFindingNo(textbox1.Value, _
CDate(textbox2.Value), 1)

You also have to do some error handling.


mfG
--> stefan <--
 

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