Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Software > Access Forms > Cmd Button Does...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 44637 of 46474
Post > Topic >>

Cmd Button Does not work on first click

by =?Utf-8?B?VGl0YW5pYVRpTzI=?= <TitaniaTiO2@[EMAIL PROTECTED] Aug 6, 2008 at 02:14 PM

I have a command button on a form that does not work on the first click. 
If 
I pause and click a second time it works perfectly.  What am I missing?

Thanks for the help
Titania

Code behind button:
Private Sub cmdClose_Click()

  On Error GoTo ErrorHandler

  Dim rs As DAO.Recordset
  Dim ctl As Control
  Dim varItem As Variant
  Dim strSQL As String
  Dim i As Integer
  Dim WasAdded As Boolean
  Dim stDocName As String
  Dim stLinkCriteria As String

 Set ctl = Forms!frmAssignSopsToEmployee.lstboxSOPSToChooseFrom

  WasAdded = False
  ' open a recordset
  Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblTraining")

  'loop thru the items in the list box
  For i = 0 To ctl.ListCount - 1
    If ctl.Selected(i) Then
      Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblTraining")
      rs.AddNew
      rs!PersonID = Me.cmbEmployeeName
      rs!Do***entNumber = ctl.Column(0, i)
      rs.Update
           
      Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblHistory")
      rs.AddNew
      rs!Do***entNumber = ctl.Column(0, i)
      rs.Update

      ctl.Selected(i) = False  'clears the selection
      WasAdded = True
    
    End If
  
  
  Next i

  If WasAdded Then
  


Exit_cmdClose_Click:
 Exit Sub

Err_cmdClose_Click:
    MsgBox Err.Description
    Resume Exit_cmdClose_Click
  End If
  
  
    

    stDocName = "frmSOPHistory"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Here:
  On Error Resume Next
  rs.Close
  Set rs = Nothing
  Exit Sub

ErrorHandler:
  MsgBox Err.Number & vbCrLf & Err.Description
  Resume Exit_Here

End Sub
 




 3 Posts in Topic:
Cmd Button Does not work on first click
=?Utf-8?B?VGl0YW5pYVRpTzI  2008-08-06 14:14:00 
Re: Cmd Button Does not work on first click
Piet Linden <PieterLin  2008-08-06 14:34:41 
Re: Cmd Button Does not work on first click
=?Utf-8?B?VGl0YW5pYVRpTzI  2008-08-07 06:08:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 20:20:09 CST 2008.