calling sub in access vba

I have some code that works but is cumbersome to use.

with z as a variant I made calls like this:

z = Decode("Abi", "polo")
z = Decode("Abi", "xc70")
z = Decode("Abi", "208")

It would pass the values and do its job.

I didnt want to hand write every call so now I have a table of clients and a table of vehicles "to do"

I wrote this to create the string based on vehicles that need doing:

Public Function MakeStrCall(Str1 As String, Str2 As String, intType As Integer, Optional Str3 As String) As String
Dim StrOut As String
Dim DecodeStrFront As String

Dim StrEnd As String

Dim CleanStrFront As String
Dim StrComma As String



StrComma = ","
StrEnd = ")"

If intType = 1 Then
    CleanStrFront = "BtnPrepareData_Click("
    
    
    StrOut = CleanStrFront & Str1 & StrComma & Str2 & StrComma & Str3 & StrEnd

Else

    DecodeStrFront = "Decode('"
    StrOut = DecodeStrFront & Str1 & "'" & StrComma & "'" & Str2 & "'" & StrEnd
End If




MakeStrCall = StrOut

End Function
Private Sub CmdDecode_Click()
Dim Db As DAO.Database
Set Db = CurrentDb()
Dim rstRangetoProcess As DAO.Recordset


Dim strSQL As String
DoCmd.SetWarnings False
Dim z As Variant

strSQL = "SELECT TblClients.ClientName, TblWishlist.RangeToProcess, TblWishlist.Marque" _
& " FROM TblClients, TblWishlist" _
& " GROUP BY TblClients.ClientName, TblWishlist.RangeToProcess, TblWishlist.Marque;"


Set rstRangetoProcess = Db.OpenRecordset(strSQL)
Dim StrFunctionString As String

With rstRangetoProcess

    .MoveFirst
    countRecords = .RecordCount

    'cycle through the recordset
    Do Until rstRangetoProcess.EOF
    
        StrFunctionString = MakeStrCall(.Fields("ClientName").Value, .Fields("RangeToProcess").Value, 2)
       z = StrFunctionString
     Debug.Print z
    
    rstRangetoProcess.MoveNext

    Loop
End With



'old way
'z = Decode("Abi", "polo")
'z = Decode("Abi", "xc70")
'z = Decode("Abi", "208")

Open in new window


an example of its output: Decode('Abi','208')

if i now do
 z = StrFunctionString  it doesnt work anymore, so would like advice on how to achieve.
PeterBaileyUkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
You can't. But you could do:

Do Until rstRangetoProcess.EOF
    z = Decode(.Fields("ClientName").Value, .Fields("RangeToProcess").Value)
    rstRangetoProcess.MoveNext
Loop

/gustav
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PeterBaileyUkAuthor Commented:
thx
0
Gustav BrockCIOCommented:
You are welcome!

/gustav
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.