PeterBaileyUk
asked on
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:
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.
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")
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You are welcome!
/gustav
/gustav
ASKER