How To Create A File With Code

  • Thread starter Thread starter Jone
  • Start date Start date
J

Jone

Hi Everybody!
What code do I have to write to make a file, for example I want to make an
activation option in my database that when the password is typed in, the
database would make an empty file for example security.exe
Any help please post
 
Jone said:
Hi Everybody!
What code do I have to write to make a file, for example I want to make an
activation option in my database that when the password is typed in, the
database would make an empty file for example security.exe
Any help please post

You assign an integer that you use to reference that file:
FreeFile automatically picks a number that is not being used.
You don't have to use FreeFile, you can just assign it a number, but it's
safer to let the machine assign the number, becuase sometimes in
development, processes end unexpectedly.



Dim fNum As Long
dim strFile as string 'this is the full path.

fNum = FreeFile
Open strFile For Output As fNum


You then have to close strFile it as part of the exit process, otherwise it
will stay open.
 
No I meen to create a file once, and it should save it let's say, in
C:\Windows\System32\example.exe
I just need a code to make this happen,then I have the code to check if that
file is there every time I open that database
 
When I dimensioned strFile as a string, indicating it was the full path, I
meant that at some point you would put the pathname in the variable strFile:



Sub CreateAFile
Dim fNum As Long
dim strFile as string 'this is the full path.

strFile="C:\Windows\System32\example.exe"

fNum = FreeFile
Open strFile For Output As fNum

'do something here

Close fNum

End Sub
 
But will that file delete when I Close fNum?

I just want to an empty file the same way you right click and press new file
on the desktop because every time I will open that database it will check for
that file and if it's not there it will ask me for the reg. code, but I don't
want that to come up every time just untill I register that for the first time
 
I know that,
All I want is code to create any file for example
C:\Windows\system32\sample.exe that's it
 
To check whether a file exists or not, you can use:

If Len(Dir("C:\Windows\System32\example.exe")) > 0 Then
' File already exists
Else
Call CreateAFile
End If
 
OK it works great! but it does not work if I put it in a system folder for
example C:\Windows\System32\example.exe (I have Windows Vista) so how do I
make that warning should come up like every other program that tries to
access the system folder and also what code do I write if I want to delete
this file
 
In my opinion, you should respect the Vista security model and not try
writing to restricted areas.
 
The VBA Kill statement deletes a file:

If Len(Dir("C:\Windows\System32\example.exe")) > 0 Then
Kill "C:\Windows\System32\example.exe"
End If
 
Back
Top