JavaToPerlNowVB
Programmer
I have an access form for user to login (username, Password) and depend on the user I want to link tables with the background sql database. In my tables I have a column to save the username at each login in time. Is there any place I can look into get some information to write this code.
This is what I did sofar, and Looks like i am going in the wrong direction....
and I am using another module to keep my global Var's here are those..
Thank in advance for any kind of help.
A
This is what I did sofar, and Looks like i am going in the wrong direction....
Code:
Option Compare Database
Public Function getDSN()
If IsNull(DLookup("[DSN]", "Database Status", "[Key] = 1")) Then
globalDSN = ""
Else
globalDSN = DLookup("[DSN]", "Database Status", "[Key] = 1")
End If
End Function
Public Function databaseStatus()
Dim groundLineDB As Database, groundLineRS As Recordset
Dim Msg As String
Set groundLineDB = DBEngine.Workspaces(0).Databases(0) 'Set MyDB to the current DB
'Truncate the table
Set groundLineRS = groundLineDB.OpenRecordset("Database Status", DB_OPEN_TABLE) 'Open TableName
groundLineRS.MoveFirst
If groundLineRS.EOF Then
Msg = "Problems with the table 'Database Status'" & Chr(13) & Chr(10) & "See your programmer"
MsgBox Msg, 64
Else
groundLineRS.Edit
groundLineRS("DSN") = globalDSN
groundLineRS("LoginId") = globalUserName
groundLineRS("Password") = globalPassword
groundLineRS("LinkStatus") = globalLinkStatus
groundLineRS.Update
End If
'Close Tables
groundLineRS.Close
groundLineDB.Close
End Function
Public Function changeLink(groundLineTable As String) As Integer
'changes a link to the data source in the globalDSN
On Error GoTo err_changeLink
Dim isDropLink As Integer
isDropLink = dropALink(groundLineTable)
If isDropLink Then isDropLink = makeALink(groundLineTable)
changeLink = True
exit_changeLink:
Exit Function
err_changeLink:
MsgBox Error$
changeLink = False
MsgBox "Link failes on:" & groundLineTable, 64
Resume exit_changeLink
End Function
Public Function relinkAllTables(groundLinePWD As String) As String
'This function relink all the tables with globalDSN
Dim linkStatus As Integer
linkStatus = True
linkStatus = changeLink()
End Function
Public Function dropALink(groundLineTable As String) As Integer
On Error GoTo err_dropALink
Dim localGndLineTable As String
localGndLineTable = "dbo_" & groundLineTable
dropALink = True
exit_dropALink:
Exit Function
err_dropALink:
MsgBox Error$
dropALink = False
MsgBox "Link drop failed on:" & groundLineTable, 64
Resume exit_dropALink
End Function
Public Function makeALink(groundLineTable As String) As Interger
On Error GoTo err_makeALink
Dim databaseName As String
Dim localGndLineTable As String
databaseName = _
"ODBC;DSN=" & globalDSN _
& ";UID=" & globalUserName _
& ";PWD=" & globalPassword _
& ";LANGUAGE=us_english;"
localGndLineTable = "dbo_" & groundLineTable
DoCmd.TransferDatabase asLink, "ODBC Database", _
databaseName & "DATABASE=pgis1", acTable, groundLineTable, localGndLineTable
makeALink = True
exit_makeALink:
Exit Function
err_makeALink:
MsgBox Error$
makeALink = False
MsgBox "New link failed:" & groundLineTable, 64
Resume exit_makeALink
End Function
and I am using another module to keep my global Var's here are those..
Code:
'Global Variables
Global globalDSN As String
Global globalUserName As String
Global globalPassword As String
Global globalLinkStatus As Integer
Thank in advance for any kind of help.
A