Are you able to use ms access vba to code access to automatically detect a computer for example *c:users\(name of the computer eg. ERICK\PDF EXPORTS\FILE NAME??? I don't want to write manually the name of the computer when exporting to pdf
Are you able to use ms access vba to code access to automatically detect a computer for example *c:users\(name of the computer eg. ERICK\PDF EXPORTS\FILE NAME??? I don't want to write manually the name of the computer when exporting to pdf
i store all client PCs that I export data using their I.P. address.
ex:
bob smith, 10.15.5.6, acctg
Code:vTarg = "\\" & txtIP & "\c$\temp\MyFile.xls" vSrc = "c:\apps\MyFile.xls" filecopy vSrc , vTarg
Option Compare Database
Function FileExist(FileFullPath As String) As Boolean
Dim value As Boolean
value = False
If Dir(FileFullPath) <> "" Then
value = True
End If
FileExist = value
End Function
Private Sub cmd_exportPDF_Click()
Dim fileName As String, fldrPath As String, filePath As String, LValue As String
Dim answer As Integer
Dim rst As Recordset
fileName = "ALL BOYS(MALES)-" 'filename for PDF file*
fldrPath = "C:\Users\ERICK\Desktop\PDF Exports" 'folder path where pdf file will be saved *
(Instead of ERICK code to detect the name of the computer automatically)
I am getting an error!
Run-time error '76' Path not found
Here are 2 functions I learned about years ago.
Good luck.Code:Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long 'Obtained from accessd group Bill Mitchell Aug 31, 2000 Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long 'Obtained from accessd group Bill Mitchell Aug 31, 2000 Function CompName() ' returns: machine name, e.g.: ' MONORAILPC Dim s As String, n As Long n = 255 s = Space(255) If GetComputerName(s, n) > 0 Then CompName = Left(s, n) Debug.Print "Computer is: " & CompName MsgBox "This computer is : " & CompName End If End Function Function UserName() ' returns: user name, e.g.: ' William Mitchell Dim s As String, n As Long n = 255 s = Space(255) If GetUserName(s, n) > 0 Then UserName = Left(s, n) Debug.Print "User is: " & UserName MsgBox "This computer user is : " & UserName End If End Function
wow that code was from 20 years ago
Bill,
Yes it is. I remember you giving me that code and some related advice. I mentioned this in the other forum.
I did not see you participating in the forums until just recently.
I have created a module and has worked perfectly well giving me the computer name and computer username. The problem is calling this function to vba code.
I want it to fit here
*C:\users\computer username extracted from the module\desktop\PDF EXPORTS"
Concatenate:
"C:\users\" & UserName() & "\desktop\PDF Exports"
Might want to disable or remove Debug.Print and MsgBox lines.
Or use intrinsic Environ() function (some people don't trust it).
"C:\users\" & Environ("USERNAME") & "\desktop\PDF Exports"
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
See these links for three ways of getting user name & computer name using VBA: Environ/WScript/APIs:
http://www.mendipdatasystems.co.uk/g...ame/4594424315
http://www.mendipdatasystems.co.uk/g...ame/4594488772
Of the 3 methods, I recommend using WScript as its both simple & cannot be spoofed
June7
You are genius. That really worked. Be blessed. Thank you so much.
Thank you guys for your help. I really appreciate. God bless you all. You have really assisted me. Thanks once again.