Solved

Access 2013 - variables

Posted on 2015-02-10
11
152 Views
Last Modified: 2016-02-11
My OS is win 7 prof 64 bit and i use Access 2013.  i have a small form that has code.
i have a variable say, pwd which is dim as a string.  
If pwd is assigned as, after some routines,  ; "123456"
How do I code to assign the "123456' to a function.  
like : randomize (123456) because when I insert the variable it does not work.  
Thank u.
0
Comment
Question by:jegajothy
  • 6
  • 4
11 Comments
 
LVL 18

Expert Comment

by:Simon
ID: 40601841
Hi,

My solution to this previous question of yours had an example of this.

In the TestIt sub that I included there to demonstrate the function, I pass it a string value:
RandomiseString("1234TqRi*(Ka")

If you already have a string variable you can pass that in place of the string
DIM x as string
DIM myResult as string

x="12345"
myResult=RandomiseString(x) 'pass the variable to the function and store the return value in the variable 'myResult'
msgbox myResult 'Display the randomised version of the original string

Open in new window


Looking at the way you've written your example above, you may have used the NUMBER 12345 instead of the STRING "12345" as the parameter for the function. However, that still works and returns a randomised STRING representation of the input number.
0
 

Author Comment

by:jegajothy
ID: 40602084
in response to SimonAdept, thank u for your response.  The string that I am passing to the Function, consists of Numbers + Ucase + Lcase + special characters.  The number of each of these, will be dependent on the user's input, i.e. if the User wanted 2 numbers, and 2 Ucase, and 2 Lcase and 2 special characters, thus making the string 8 characters long.  
My problem is I cannot seem to pass a variable into the Function, like :
Test = randomizestring (pwdtoarrange)
pwdtoarrange is declared as a string, and say it has been passed : "789few&", during the above assigning process.  
Not sure whether it is the way version 2013 behaves or not. thank u.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 40602187
Just curious...

Whats the need to create a variable, and then randomize it...
What not just create a random string to begin with...?
0
 
LVL 18

Expert Comment

by:Simon
ID: 40602538
Can you tell us more about the symptoms of it not working?
Are you getting an errror message? If so, please post it.
Have you tried stepping thru the code using the toolbar button or setting a breakpoint and then using the F8 key?
Have you tried right-clicking the variable and setting a watch on it so you can see its value after each line is executed?
0
 

Author Comment

by:jegajothy
ID: 40603159
in response to SimonAdept, From the form, i passed the Function into a variable, like strresults = randomizestring (pwd) and pwd's value is a string of " ABxi96@! ".   but when i examined the variable, the result was not passed.  When I stpped into the program, The program executed each line correctly and i did not observe any errors.  
But if i were to put a msgbox inside the Function to see the results, it displays correctly the returned result.
Thus, I am at a lost.
The function is located at the Module.

I was thinking of declaring a global variable inside the Function, that will be visible outside the Function, if u think this will work, can u please let me know what is the syntax to declare this variable, and also where it should be declared, i.e. at the Module below Option Explicit where the Function is located or at the Form level.

I have tried relocating the Function at the Form level, but the variable still is not changed after the Function had been executed.

Thank u for your advise.
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 18

Expert Comment

by:Simon
ID: 40603372
Ahh, did you use the code from the first version I posted on your previous question rather than the version you marked as the solution? In the first version I had omitted the line that provided the return value. The correct version of the function is:
Function RandomiseString(inputString) As String
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
End Function

Open in new window


Line 10 in the listing above is the key one. It assigns the internal result to the function name, which is the return value of the function.
0
 

Author Comment

by:jegajothy
ID: 40603432
in response to SimonAdept, thank u for your response.  But how do i access the contents of the result from the Main form, is it like this;
 strresult = ??
rather than make u laugh of my being very basics, hope u could please give me the syntax.  Thank u.
0
 

Author Comment

by:jegajothy
ID: 40603450
in response to Jeffrey, the app is a password creation tool, where the user will specify how many letters, numbers and special characters that the result should be.  In order to make it doubly more difficult for anyone to guess, thus i thought I would rearrange by randomizing the result string.   thank u for your suggestion.
0
 
LVL 18

Accepted Solution

by:
Simon earned 500 total points
ID: 40603699
In your main form, if you want a calculated value in a textbox, make its datasource
=randomiseString(nameofControlThatHasTheInitialStringValueIn)

Or, if using VBA and you want the value to go into a textbox called txtFinalPassword
a) take the initial value to randomise from another control on the form.
me.txtFinalPassword = randomiseString(me.nameofControlThatHasTheInitialStringValueIn)
B) if you have the string already in a variable named 'pwd'
me.txtFinalPassword = randomiseString(pwd)
0
 

Author Comment

by:jegajothy
ID: 40604752
In response to SimonAdept, thank u for your suggestions.  i did create a new field as suggesed, but somehow I did not have any success in passing the return value of the function to the me.txtFinalpassword.  i brought the function from the Module to the Form level, but that still not work.  But when I inserted the syntax inside the Function, the field got populated with the changed value.  
although it is a bit unorthodox, but the result worked.  thus i have he original value before passing into the Function and the changed value after processing by the function.  Thank u for all your suggestions, and with best wishes.
0
 

Author Closing Comment

by:jegajothy
ID: 40604753
thank u.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Track name AutoCorrect info 14 47
Merging-Splitting-Multiple-Rows 33 44
MS-Access 2002 error (Win XP on Win7Pro) 19 49
Access 2010 Query Syntax 5 23
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

896 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now