Hi all, Im struggling a little with this. Can anyone help me?When I run the code I get "Run-time error '3709': The connection cannot be used to perform this operation. It is either closed or invalid in this context."Private Sub btnAdd_Click() Dim UserName As String Dim Initials As String Dim Password As String Dim OutlookName As String Dim cnCurrent As New ADODB.Connection Dim rsUsers As New ADODB.Recordset'Check each control, is their a value? if not, set focus to controlIf IsNull(txtUserName) Then MsgBox "You did not enter a new UserName nobby!" Me!txtUserName.SetFocus Exit Sub ElseIf IsNull(txtInitials) Then ' return value of UserName variable; MsgBox "You have not entered any initials for user: '" & Me!txtUserName & "'" Me!txtInitials.SetFocus Exit Sub ElseIf IsNull(txtPassword) Then MsgBox "You must create a password for user: '" & Me!txtUserName & "'" Me!txtPassword.SetFocus Exit Sub ElseIf IsNull(txtOutlookName) Then MsgBox "You must enter a Outlook name for: '" & Me!txtUserName & "'" Me!txtOutlookName.SetFocus Exit Sub End If' Pass the variables to the table.cnCurrent.ConnectionString = "Provider=sqloledb;Data Source=PE750-D;Initial Catalog=HSS;Trusted_Connection=yes;"MsgBox "Connection OK"Set rsUsers = New ADODB.RecordsetrsUsers.Open "Users", cnCurrent, adOpenDynamic, adLockPessimistic, adCmdTable With rsUsers .AddNew ![User] = Me!txtUserName ![Password] = Me!txtPassword ![Initials] = Me!txtInitials ![OutlookName] = Me!txtOutlookName ![Level] = 1 ![Select] = 0 ![dummy] = Null .Update .Close End With Set rsUsers = NothinglblAdded.Visible = True If MsgBox("The user: '" & Me!txtUserName & "' was successfully added. Do you wish to add another?", _ vbYesNo, "Information") = vbYes Then DoCmd.Close DoCmd.OpenForm "Add_User", , , , , acDialog Else DoCmd.Close End IfEnd Sub
when life hands you lemons, ask for tequila and salt 