Hi There,
I currently have all my tables in MS SQL and they are connecting in the standard way (used the external data section to link to the tables through ODBC in Office 2007 and the MS SQL 2005 Native Client).
I was wondering if there was a way in VBA before my database does anything, to specify a different username/password to connect to the SQL server with? I have 2 SQL Authentication usernames (one is read-only) and I have the two DSN files with the slightly different usernames and passwords in them.
Is there a way in VBA to specify different username and password OR to choose a different DSN file to use?
Thanks.
Matt.
6 6338
Thanks but that didn't work. It's really old code, and just wouldn't work in Access 2007 - threw no errors, but I was still getting prompted if there was no username and password, or it just wouldn't open the tables.
I tried this: -
For Each X In CurrentDb.TableDefs
-
If Not X.Properties(4) = "" Then
-
strXProp = X.Properties(4)
-
strXProp = Replace(strXProp, "normal", "readonly")
-
strXProp = Replace(strXProp, "1234", "abcd")
-
X.Connect = strXProp
-
X.RefreshLink
-
End If
-
Next X
-
but it doesn't work straight away. Instead it saves that to the tables properties (which is OK because I can just do the reverse when I need to) - but it means that I have to restart access, which isn't ideal.
I did look at an ADP - but coding in that would be quite different to a MDB (I already found a few functions that didn't work just in my basic testing)
nico5038 3,080
Recognized Expert Specialist
For relinking tables you can use this code: -
Function fncRelink()
-
'function to relink tables to the "_be" database
-
'It's assumed that the "_be" database is in the same folder as the frontend !
-
-
Dim td As DAO.TableDef
-
-
For Each td In CurrentDb.TableDefs
-
If Len(td.Connect) > 0 Then
-
td.Connect = ";DATABASE=" & Left(CurrentDb.Name, InStrRev(CurrentDb.Name, "\")) & Mid(td.Connect, InStrRev(td.Connect, "\") + 1)
-
td.RefreshLink
-
End If
-
Next
-
-
MsgBox "Ready, tables relinked"
-
-
End Function
-
You'l have to edit the td.Connect to reflect the needed userid and password. Just open a linked table in design mode and check the properties, as it will show the link used.
Nic;o)
That's basically the same code, and it's what I started with (which didn't work) before I turned it into that. Property 4 is the same as connect.
All I did was just replace the old username and password with the new one.
And it's not another database that I need to connect to, it's the same SQL server - just need to change the username and password.
Thanks anyway.
Looks like we will just have to go with ADP.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Bob Rivers |
last post by:
Hi,
I have an application that uses jdbc (9.2.0.3/classes12) to connect to
an Oracle db (9i). It works fine, except when the user password is
going to expire.
Let me try to explain (sorry my...
|
by: Bright |
last post by:
Dear All
I'm after a multi-User password database so that I can centrally store
system passwords and give granular access to individuals based on
their own unique authentication (possibly a...
|
by: Daniel |
last post by:
Hello everyone,
I am trying to connect to a password protected Access database using:
Public connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & pathDB & ";User...
|
by: Bernard Lebel |
last post by:
Hello,
I would like to know if there is a way to run a Python file under a
different user account than the one logged in. Allow me to explain.
There are a bunch of people here, they are "basic...
|
by: webrod |
last post by:
Hi all,
how can I check a user/password in a LDAP ?
I don't want to connect with this user, I would like to connect to LDAP
with a ADMIN_LOG/ADMIN_PWD, then do a query to find the user and...
| |
by: ranju |
last post by:
I am trying to spawn a process (say an exe file) with different user
crendentials than that of the current user.
1) Called LogonUserEx() to logon the user and recieve a handle to the
token that...
|
by: Oliver |
last post by:
Newbie, looking at DB2 on AS400 iSeries, on Windows network. I have
read that users are authenticated at the OS level, not at the database
level.
How do I make it possible for users to change...
|
by: julia.druce |
last post by:
I can't seem to launch a process as a different user and hide the
window as well. If i don't specify the user, my window launches
hidden. But when I specify a user, the executable.exe process...
|
by: =?Utf-8?B?SHVleQ==?= |
last post by:
I need to hide the new window started from the code below. If I run as is,
the window is visible. If I comment out the code that sets a different user,
domain, and password the window is hidden...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |