代码无需输入密码 [英] Code To eliminate need to enter password

查看:62
本文介绍了代码无需输入密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个访问表单,该表单将来自不同表的数据汇总在一起.其中一些要求输入用户名和密码.这正在向其他用户发出,我希望他们不必一遍又一遍地输入信息.每当提示您输入密码以使其自动登录时,我是否可以使用该代码?

I have an access form that pulls together data from different tables. Some of them require a username and password be entered. This is going out to other users and I would rather them not have to enter the information over and over. Is there a code that I can use that whenever it prompts for a password to have it automatically logged in?

当前,我已经有一个数据库连接的连接,只要打开数据库,该连接就会运行.看起来像:

Currently I already have a connection for one DB connection that runs whenever the DB is opened. It looks like:

Public Function StartUp()
Dim cnn As ADODB.Connection
Dim localrst As New ADODB.Recordset
Dim remoterst As New ADODB.Recordset

On Error Resume Next
Set cnn = New ADODB.Connection


cnn.Open "Provider=SQLOLEDB; Data Source=SOURCE; Initial Catalog=NAME;" _
& "User Id=ID; Password=PW;"

If cnn.State = adStateOpen Then
MsgBox ("You have an established connection with the L&TD SQL Server Database and the CDData     table has been uploaded to the server.")
Else
MsgBox ("Cannot connect to SQL Server. Data will be stored locally to CDData Table until application is opened again with an established connection.")
End If
On Error GoTo 0


End Function

有没有办法为此添加更多的连接,使其连接到所有3个?

Is there a way to add more connections to this so it connects to all 3?

推荐答案

字面上的答案是;不.您无法使密码表单自动填充.但是,您可以设置连接字符串,这样就无需填写它.

The literal answer is; no. You can't make a password form autofill. However, you can set up your connection string so that no one has to fill it in.

'Set up the connection string
        strConn = "PROVIDER=SQLOLEDB;DATA SOURCE=MyServerName;INITIAL CATALOG=MyDatabaseName;UID=MyStandardUserID;PWD=MyStandardPassword;"
        cnComments.Open strConn

您也可以不使用用户名和密码进行设置:

You can also set it up without the username and password:

'Set up the connection string
        strConn = "PROVIDER=SQLOLEDB;DATA SOURCE=MyServerName;INITIAL CATALOG=MyDatabaseName;TRUSTED_CONNECTION=yes;"
        cnComments.Open strConn

这篇关于代码无需输入密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆