Modules & VBA :: Retrieving User Name Logged Into Windows?
Sep 20, 2013
Continuing with production of my database I've come across another wall that I'm trying to pass. My aim is when the user press the "Quit" button it will export everything to a file which is stored on Google Drive as google drive is installed on the laptops that will be using this database.
However the problem is Google drive is stored in the computer user files i.e C:UsersstudentGoogle Drive - is there a way to retrieve the name of the user that is logged into windows?
Code:
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal IpBuffer As String, nSize As Long) As Long
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Function ThisUserName() As String
Dim LngBufLen As Long
Dim strUser As String
[code]....
However cant get this to work - I think that is probably because i'm declaring this code in the wrong place - I've tried declaring the private functions in a class module and the functions in a module - however no success - How do you set this code up? Or is there a new way to do this?
I found this database with an LOGIN sample. This is working perfectly...(see example)
Now I want to accomplish this:
Based on the user that is logged in I want to generate reports. Is there a way to recall the username or userID and link that to specific reports...
Allso I want to add an mail adress field in the userstable and based on the logged in user I want to hit a mail button and it will check the logged in user... and mail the report to that specific user...
I used the following script "GetCurrentUserName()" in access 2003 to get the username of the logged user. I’m using the following script "CurrentUser()" in access 97 but it always recognise any user as a admin. Is there anyone that could tell me how to solve this please? Thanks
In an network environment that requires users to log in, is there any way for Access to record a user who opens an Access application. The application has no security applied to it. The .ldb has the users listed, but can the .mdb put it into a list inside the .mdb?
At this point, FE db has 4 linked tables, 3 are located in FileBE1, and the 4th is located in FileBE2.
The production BE is located on a server, the test (when working remotely) is on a local computer that is not able to connect to the server. Also, the test BE files (but not the table names) have different names than the production.
I have the idea of creating a table in the Front End that contains a list of users, filename and location (server or local drive).
Upon startup, how could I set up the vba to check the links and if they need to be changed will go and change them without the user having to click on link table manager or be prompted for names and path.
For now, I envision three rows in the table, one for the test user, one for local user and a default UNC for everyone else. (or would it be six rows since there are two files that need link checking and relinking).
I have some code that when a check box in a table is ticked, sends a pop up message to the users logged in (message is on a hidden form), then it closes the DB after a pre-dtermined period of time.
The problem I'm having is that we are a large site with a about 25 differnet servers that our users log onto via Citrix, when a user is on a different server it isn't displaying the message nor closing the DB down.
trying to achieve this? Or is there a better way to see who is logged in and get a message to them?
I'm using Access 2003 btw
Code I'm using below
Code: Option Compare Database Private Sub Form_Load() Me.TimerIntderval = 10000 ' change to 300000 for about 5 minutes End Sub Private Sub Form_Timer() DoCmd.Close Application.Quit End Sub
Hi Guys, my first post hereim making a database for work and need to figure out the followingi have two people that uses a ms access db, each entering data.i made a custom macro in the vb editor:Public Function cUsername() cUsername = Environ("USERNAME")End Functionwhat i want to do now is, everytime a new entry is added in the table, it should add that username to the "user" cell... it should only do this once, so for example, when i enter data it will show "albert" and if i was to close it, login as "steve" it should still show "albert" under the ones i added, and not steve...this needs to be in the table not a query or form...thanks for your timeAG
I have several data entry forms in my DB. What I would like to do is capture the windows user name of the people adding records and changing records. How do I go about doing that? I was think of an on change event to a given field that would then pull the username and insert it in another field/object.
Lets say the an on change of me.cmbModel update txtUserName.
Im seeking for a solution to prompt all user with windows alert for Notification
Case 1:One staff applied leave and clicked "Submit" , after clicked I want the system will prompt his/her Supervisor for his/her leave approval or like a notification that the Supervisor need to go somewhere to approve (Selected Supervisor)(Maybe the Supervisor need to 7x24 Opening the access database).
I have an Access Database that I will be using on a desktop. I have a table in this database that mirrors the structure of a table on a remote server in a SQL database. I have successfully created a vba function within the Access database that uses a server-side php subroutine to select records (I usually won't know how many) from the SQL database and return them to the access database. The code I use in the access vba subroutine to access the php subroutine is:
Code: With CreateObject("Shell.Application").Windows Set ieWindow = CreateObject("InternetExplorer.Application") ieWindow.Visible = False apiShowWindow ieWindow.hwnd, SW_MAXIMIZE ieWindow.Navigate "Web address for server-side php file" End With
The last command in my php subroutine is "return $retrievedData." $retrievedData is a multidimensional array containing data from 42 fields in multiple records (again, I usually won't know how many). I've checked the data in php so I know it has been stored correctly.how do I access the returned data within my access vba subroutine?
I should add that my overall reason for doing it this way is that I want to maintain my server-side database as an untouched master. Users can only add data to it. My client-side database is used to update the input table and further process the data. The subroutines described above are intended to retrieve "new" records only (i.e., records posted since the last access database update) from the server-side database and transfer them to the access database for further processing.
Public Function OdometerInput(varodometer As Variant) As Long Dim varKilometres As Variant varKilometres = varodometer * 1.609344 OdometerInput = CLng(varKilometres) End Function
It works fine in the immediate window (although I haven't just fathomed what to do with null values and such) But my question which I am sure will be 'easy when you know' is how do I pass the variable to it from a text box on a form and retrieve the data in another text box on a form.
Front end Access 2010, back-end SQL-server 2008 R2.
Normally I retrieve a certain value by Dlookup("myvalue", "mytable",...)
or
strSQL = "SELECT myvalue FROM mytable...;"
Set rs = CurrentDb.OpenRecordset(strSQL, 4)
But is there any faster way to retrieve a single value from an SQL-server table, beside doing doing the select by a stored procedure running through a pass through query, then open a recordset
Set rs = CurrentDb.OpenRecordset("mypassthroughquery")
just to retrieve ONE value?
I could not find something like DLookup("...) for an SQL-Server or in T-SQL.
I have a website that is asp (not .net) based with an Access DB and I am in the process of replacing an old windows 2000 server with a much faster windows 2003 server. Here lies the problem I have a script as part of the admin that exports data to a csv file. The query joins 4 tables together to get the data needed for the export. On the windows 2000 server it takes 1-5 seconds to execute and have the csv file ready for download. On the window 2003 server it times out. I striped it down to use 2 joins and it worked although it took more like 10-20 seconds to export. This exports a specific range of ID's and the range is normally only 40-50 rows. If I put time stamps in the code the problem is in the query of the database, so I know its not in the file write etc.
I am going to rewrite it to use multible querys instead of one large query, but I have many other sites that I am moving to this server that would work better if I can figure out why it is so slow.
The windows 2000 is a 900 mhz server the windows 2003 is a 2.8GHZ server both have 1 GIG of ram. The database file is on the local drive on both servers. I am guessing it is a difference in the Jet version, I just haven't been able to find a solution to the problem. This uses a DSN connection, configured the same on both servers. I have also tried it as a DSN-less connection with the same result.
I have installed access on the server and to execute the command in access it is <2 sec.
I am not an access expert I normally program in .net and php and use MySQL and MsSQL for databases, we just have these legacy sites that use Access DB's
I write Access 2010 apps in VBA that require no knowledge of Microsoft Access on the part of the user. My forms contain all the necessary controls to use the program without relying on any of the Microsoft Access toolbars. I call this "de-Microsofting" the app. When I prepare the .accdb program to create a .accde app, I uncheck every checkbox (Options/Current Database) except "Compact on Close". This works well, but it also hides the Windows taskbar at the bottom of the screen. Some of my users need to be able to jump from my app to others (e.g., Excel) and back without having to exit my app. How can I force the Windows taxkbar to always be on top using VBA or, possibly, some setting?
I have an application that is using SQL Express as a backend and syncing to a SQL database through SQL web synchronization. This all works great and my clients have my custom application to interface with their local database and do work and it syncs back to the corporate database and I've got it scheduled to run in Windows every minute. What I would like to do is have a button or on event set of code that forces that sync pairing to run and I'm not exactly sure how to do that.
I have a vbs-script that opens my access database db.mdb and runs the module "Export":
dim accessApp set accessApp = createObject("Access.Application") accessApp.OpenCurrentDataBase("D:Datadb.mdb") accessApp.Run "Export"
accessApp.Quit set accessApp = nothing
This works fine as a scheduled task on a Windows 7 computer.
Is there a way to make this work on a Windows Server 2008 R2 ? When I double click the vbs-file, the file opens instead of runs. And when I create a scheduled task, nothings happens.
On the Windows 7 Developer desktop, the Windows Theme is set to Windows 7.On the Citrix server (for users) the Windows Theme appears to be Windows 95. It is low graphics.The boxes are square instead of rounded. The selected Form Tabs just barely highlight with a thin line while on Windows 7, the selected Tab completely changes color. A basic Message box in Windows 95 looks square and flat. The title bar is very low graphics as one would expect when graphics were not great. Is there a VBA call that can display the OS Theme that affects MS Access? URL...
I currently have a button on a form which, when clicked, I would like to do several things:
1) Check if the folder, "folder name (1)" exists 2) If no, make it; if yes, check if the folder, "folder name (2)" exists 3) If no, make it; if yes, check if the folder, "folder name (3)" exists 4) repeat this process until a new folder is made
The code I currently have seems to not work, and makes an infinite loop
Code: Private Sub Export_Click() Dim checker As Integer Dim projPath As String checker = 1
I can currently open a new internet explorer instance, navigate to my URL, then use the .getElementByID to insert my preference into a textbox on the page. Looks like this:
Code: Dim oIE As Object Set oIE = CreateObject("InternetExplorer.Application") oIE.Navigate "URL of my Choice" Do While oIE.Busy Or oIE.ReadyState <> READYSTATE_COMPLETE DoEvents
I have always had solid read access to the Windows registry running on Windows XP with Access 2007. I am utilizing code from here in a separate VBA Module to obtain access to the Windows registry:
"Change registry settings in VBA"
[URL]
On Windows 7 x64 / Access 2010 x86, I am seeing a 0 value in lngKeyHandle. Also, m_lngRetVal has a value of 2 after the RegOpenKey LOC.
Code: ' -------------------------------------------------------------- ' Query the key path ' -------------------------------------------------------------- m_lngRetVal = RegOpenKey(lngRootKey, strRegKeyPath, lngKeyHandle) ' -------------------------------------------------------------- ' If no key handle was found then there is no key. Leave here. ' -------------------------------------------------------------- If lngKeyHandle = 0 Then regQuery_A_Key = vbNullString m_lngRetVal = RegCloseKey(lngKeyHandle) ' always close the handle Exit Function End If
I have verified that I have the key successfully in the registry... installed via the .reg file that works on Windows XP / Access 2007 systems.