I think I've spotted the error. Its to do with name conventions.
it difficult to see what ServerID is if ServerID is a global variable/table column and textfield. So if we name the variable to gblServerID then where ever you see that name you will know its refering to the global variable.
Having a look at your login form why is it based on a table? i.e it fetches data from the table and places it on the form. or is it just for a demo?
Sorry my fault as well its not controlsource but DefaultValue.
Now login to the attached DB. click on "Transaction" and the ServerID should be set.
What I did to get this to work?
first I change the global variable to gblServerID
Then with the login form's code I did the following:
Code:
Private Sub Command9_Click()
'Used as a where clause
Dim lSearch As String
'Build the criteria to limit the row where servername and passcode match
lSearch = "[ServerName]='" & Me.txtServerName & "' AND [Passcode] = '" & Me.txtPasscode & "'"
'check user should be able to access system
If Me.ServerName = Me.txtServerName And Me.Passcode = Me.txtPasscode Then
' Using DLookup we find the ServerID in tblServer and meets the where/criteria clause
' We then set the global variable gblServerID
gblServerID = DLookup("[ServerID]", "tblServer", l_search)
'Close login form
DoCmd.Close
'Open Main Form
DoCmd.OpenForm "frmMainMenu"
Else
'Inform the user they have not been successful
MsgBox "Password incorrect or required"
End If
End Sub
I then added a button on the main form to navigate to the transaction form.
On the transaction form I change the on load code to the following
Code:
Private Sub Form_Load()
' Only change the default value if the gblServerID is set and not 0
If (IsNull(gblServerID) = False And gblServerID > 0) Then
'Change the default value to the global variables values
Me.txtServerID.DefaultValue = gblServerID
End If
End Sub
Hopefully this helps you. If it does please add some rep points for me.