Solved

Access 2013 - variables

Posted on 2015-02-10
11
151 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:SimonAdept
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:SimonAdept
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 18

Expert Comment

by:SimonAdept
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:
SimonAdept 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 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

18 Experts available now in Live!

Get 1:1 Help Now