Я пытаюсь передать строковое значение из одной формы в другую. Моя первая форма - «frmTscLogin», содержащая пользовательский NT-идентификатор «strNtId» и пароль «strPassword» (это обычная форма входа в систему). Форма, которую я пытаюсь открыть и передать строку - это "frmTscSptAsgmt". Из frmTscSptAsgmt пользователи SPT будут назначать документы пользователям AGT, хранящимся как записи в Access. Эти записи будут содержать NT ID пользователя SPT, который назначил документ пользователю AGT, поэтому очень важно, чтобы значение strNtId передавалось из frmTscLogin в frmTscSptAsgmt.
'Project: TSC Updatabase
'Form: TSC Login Form (frmTscLogin)
'Author: Nathan Willett
'Created: 9/10/19
'Current Version: 1.0 - 9/10/19
'Previous Version:
Option Compare Database
Option Explicit
Public strProfile, strNtId, strPassword As String
'On 'Button Ok' click, perform the following
Public Sub btnLogin_Click()
'If NT Login Box is left blank, display "Please enter NT Login"
If IsNull(Me.txtNtId) Then
MsgBox "Please enter NT Login", vbInformation, "Login Error"
Me.txtNtId.SetFocus
Exit Sub
'If Password Box is left blank, display "Please enter Password"
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please enter Password", vbInformation, "Login Error"
Me.txtPassword.SetFocus
Exit Sub
End If
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("tblTscUserList", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "fldNtId='" & Me.txtNtId & "'"
'If txtNtLogin value does not equal fldNtId, prompt the user
If rs.NoMatch = True Then
MsgBox "Incorrect NT Login. Please try again.", vbInformation, "Login Error"
Me.txtNtId.SetFocus
Exit Sub
End If
'If txtPassword value does not equal fldPassword, prompt the user
If rs!fldPassword <> Me.txtPassword Then
MsgBox "Incorrect Password. Please try again.", vbInformation, "Login Error"
Me.txtNtId.SetFocus
Exit Sub
End If
'Look up the users profile version (AGT, SME, SUP, SPT...) from tblTscUserList
strProfile = DLookup("fldPosId", "tblTscUserList", "fldNtId='" & Me.txtNtId.Value & "'")
strNtId = rs!fldNtId
strPassword = rs!fldPassword
'Open the corresponding profile form
Select Case strProfile
Case "AGT"
'still developing
MsgBox "Open AGT Window"
Case "SME"
DoCmd.OpenForm "frmTscSmeAsgmt"
Case "SPT"
DoCmd.OpenForm "frmTscSptAsgmt"
Case "SUP"
DoCmd.OpenForm "frmTscSupAsgmt"
End Select
DoCmd.Close acForm, "frmTscLogin"
End Sub
'On 'Button Cancel' click, close the program
Private Sub btnCancel_Click()
DoCmd.Close acForm, "frmTscLogin"
End Sub
'Project: TSC Updatabase
'Form: SPT Assignment Form
'Author: Nathan Willett
'Created: 9/21/19
'Current Version: 1.0 9/21/19
'Previous Version:
Option Compare Database
Option Explicit
Dim db As Database
Dim rs As Recordset
Private Sub Form_Open(Cancel As Integer)
Text468.Text = frmTscLogin!strNtId
End Sub