I have a database username and password written into the VBA code of an Excel tool that is used to generate reports. The correct functionality of the form is that the user clicks a button and begins making criteria selections to generate a report. To generate the report, the Excel tool needs to read a database. With the way the Excel VBA is written, the user should already be signed in to the database via the VBA in the Excel document. You can see below in the code excerpt the green highlighting shows the user name and password hard coded into the form, and then yellow highlighting shows the action "ShowSetup()" that initiates when the user clicks the button.
However, once clicked, the button on the form displays the user name and password entry box shown below. That is not correct, it should show the user a report criteria selection screen. Can anyone explain what would cause the hard coded database credentials to be ignored?
However, once clicked, the button on the form displays the user name and password entry box shown below. That is not correct, it should show the user a report criteria selection screen. Can anyone explain what would cause the hard coded database credentials to be ignored?
Code:
Public Const DB_ATTR = "I:\sysfiles\mg_data\CSDB2.mdb"
Public DBAT As DAO.Database
Public DB2 As Object
Public WBA As Workbook
Public WSGC As Worksheet, WSGA As Worksheet, WSGI As Worksheet, WSAC As Worksheet
Public deptArr()
Public Const c_PD1 = 3
Public Const c_PD2 = 7
Public Const c_PD3 = 11
Public Const c_LAST = 14
[highlight #8AE234]Public Sub DB2Connect()
uid = "useridhere"
pwd = "passwordhere"
strConnect = UCase(DBAT.TableDefs("MRSPC_TCD301DPTCLA_GCLA").Connect) & ";UID=" & uid & ";PWD=" & pwd
Set DB2 = OpenDatabase("", False, False, strConnect)
strConnect = UCase(DBAT.TableDefs("MRSPC_TCD300GEN_CLASS").Connect) & ";UID=" & uid & ";PWD=" & pwd
Set DB2 = OpenDatabase("", False, False, strConnect)
DB2.Close: Set DB2 = Nothing
End Sub[/highlight]
Sub [highlight #FCE94F]ShowSetup()[/highlight]
Dim dCount As Integer
Dim isWBA As Boolean
dCount = 0
isWBA = False
dlgSetup.Show 1