Referencing a random number in file name

RWood86

New member
Local time
Today, 22:58
Joined
Mar 11, 2016
Messages
1
Hi Guys,

Losing my mind on this one. I am sure there is a simple fix but just cant get there!

I have a report that includes a text box that generates random numbers. I need to save the report and reference the random number in the file name. I use the Exportwithformating option in macro to do this, but each time the report saves as a pdf, becuase I am referenicng a random number generater in the text box it saves the file with a different random number to the one that has been generated on the report.

Hope that makes sense!

So, how do I get the file name to reference the value already exisiting in that text box and produced on the report, rather than generating a new number which is not helpful at all!!

Thanks in advance!
 
have a form text box get assigned when the form opens.
txtbox = rnd()
the query for the report uses this, then it wont change while the report runs.
Myself, I use a date/time stamp yymmddhhss
 
Another option would be to have a function generate the random number and then have the form check if the random number field has been filled. If not, call the function to generate a random number and insert it in the proper place. If the field has already been filled, leave it alone.

This should ensure you only get a single random number for the form each time you open it.
If you refresh the form it should do so without deleting your random number as it has done so far.
 
note also that you may need to use the instruction "randomise" before generating the random number

rnd() is set to give the same sequence of random numbers unless you randomise first - which is useful for checking that procedures are working correctly.
 
The FileSystemObject also has a random temp filename generator, which you can pull apart and use pieces of, like . . .
Code:
Function GetHexName() As String
    With CreateObject("Scripting.FileSystemObject")
        GetHexName = Mid(.GetTempName, 4, 5)
    End With
End Function
 

Users who are viewing this thread

Back
Top Bottom