Solved

Access 2013 - Help for functions

Posted on 2015-02-10
8
230 Views
Last Modified: 2015-02-10
My OS is win 7 prof 64 bit and i use Office 365 and Access 2013.
in Access 2013, I have a Form, which has the following code under a command button :

Private Sub Command29_Click()
      Dim torandom As String
      torandom = "1234TqRi*(Ka"
      MsgBox "this is what the string to randomize looks like before being randomized : " & torandom
      MsgBox (RandomiseString("1234TqRi*(Ka"))
      Debug.Print (RandomiseString("1234TqRi*(Ka"))
End Sub

The Function, RandomiseString is created in the Module, and it is as follows :

Public Function RandomiseString(inputString) As String
'-start

Dim mystr As String
Dim myStrLen As Integer
Dim random_number As Integer


mystr = inputString
myStrLen = Len(inputString)
resultstring = ""
Do Until Len(resultstring) = myStrLen
    random_number = Int(Len(mystr) * Rnd) + 1
    resultstring = resultstring & Mid(mystr, random_number, 1)
    mystr = Left(mystr, random_number - 1) & Right(mystr, Len(mystr) - random_number)
Loop
'RandomiseString = resultstring

glbconverted = resultstring
return glbconverted
MsgBox "This is INSIDE the function of the glbconverted" & glbconverted
'---END
End Function

i would like to return the result from the function to the calling Procedure, but i do not know how to do it.  And also where do I declare the variables in the Function.  I tried in the Module, but the procedure does not see it.  So looks like i am not doing things right.

Please let me know where I should  create the variable that will have its scope in the entire access program, and what is the syntax.

how does the function, return the result to a variable, that will be visible outside this function?

As i was experimenting, thus, please correct my code as necessary.  Thank u for your advice.
0
Comment
Question by:jegajothy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 12

Expert Comment

by:FarWest
ID: 40601000
commenting this line
'RandomiseString = resultstring
makes the function without return value
you should assign value to function name like above to return a value to caller
0
 

Author Comment

by:jegajothy
ID: 40601005
In response to FarWest.  Can u please give me the syntax to call the Function and to return the processed value to a variable, which I can use in the calling module.  thank u.
0
 
LVL 12

Expert Comment

by:FarWest
ID: 40601017
check this

Public Function MakeMeCapital(anystr As String) As String

    MakeMeCapital= UCase(anystr )

End Function
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:jegajothy
ID: 40601255
in response to FarWest, sorry for being so basic, but can u pse show me the syntax for assigning a variable to call this function from the body of the Form, and then I could use the result somewhere else within the same form.
Thank u.
0
 
LVL 12

Expert Comment

by:FarWest
ID: 40601283
you mean like this, you just define your variable out of any sub of function
like this
Dim nn As String

Public Sub test1()
nn = MakeMeCapital("asjjs")
test2
End Sub

Public Function MakeMeCapital(anystr As String) As String

    MakeMeCapital = UCase(anystr)

End Function

Public Sub test2()
MsgBox (nn)
End Sub

Open in new window

0
 

Author Comment

by:jegajothy
ID: 40601408
In response to Far West, i hope u do not mind if u can please take a look at the code and see where I am going wrong.  the command button is called : Generate.  and the code is attached.  Hope u can please comment on the code where the errors are or best practices could be used.  Thank u
ERROR-IN-CODE.txt
0
 
LVL 12

Accepted Solution

by:
FarWest earned 500 total points
ID: 40601439
I just have to leave my computer now
but to get value from any function either use the function name directly or assign a variable to it
example

dim ss as string
ss = MakeMeCapital("asjjs")

or
textbox1.text = MakeMeCapital("asjjs")

value or variable inside the function parentheses ("asjjs") is input parameter (unless used by reference which is not our case now)
0
 

Author Closing Comment

by:jegajothy
ID: 40601594
thank u for the solution.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question