combo box drop down value is repeating

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • squrel
    New Member
    • Jan 2008
    • 143

    combo box drop down value is repeating

    Hello everyone..

    i have a small problem here... i have a combobox in my project call cmbresult which has been filled up in the properties by using list properties... i have 4 option there... whn i add a new record its fine and by clicking the drop down the 4 option is showing and i can select and add easily bt when i want to view any selected record whtever has been set for the cmbresult its repeating 2 times... i have tried to use the set focus and get focus bt its not working...
    can anyone help me here?
    thank u very much
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    i am not sure what exactly is your problem . please post the code that youare working on.

    Comment

    • squrel
      New Member
      • Jan 2008
      • 143

      #3
      Ok here is my code which i m working on it.... plz help me.. my cmbresult is getting repeated which i m using the viewall button.. the cmbresult has been filled from the list properties
      thank u very much


      Code:
      Option Explicit
      Private Sub Form_Initialize()
       On Error GoTo ChkErr
              Db.Close
              Db.ConnectionString = pStrConnectionString
              Db.ConnectionTimeout = 0
              Db.Open
              Db.CursorLocation = adUseClient
              DoEvents
      Exit Sub
      ChkErr:
          If Err.Number > 0 Then
          MsgBox Err.Number & vbNewLine & Err.Description
                     Call ErrHand(Me.Caption, "Form_Initialize")
              'Resume Next
          End If
      End Sub
      Private Sub Form_Load()
      On Error GoTo ChkErr
           FormUpdateSQL1.ConnectionString = pStrConnectionString
          FormUpdateSQL1.TableName = "Proceedings"
          FormUpdateSQL1.FieldList = "Id;Description;CourtId;CaseId;AdvId;PersonAttend;Result;Nextdt;Reminddt;Advname;"
          FormUpdateSQL1.ControlList = "txtId;txtDescription;txtCourtId;txtCaseId;txtAdvocateId;txtPerson;cmbresult;DTPnextdt;DTPreminddt;txtadvocate;"
          FormUpdateSQL1.ViewFields = "Id;Description;CourtId;CaseId;AdvId;PersonAttend;Result;Nextdt;Reminddt;Advname;"
          FormUpdateSQL1.FormatString = "Id;Description;CourtId;CaseId;AdvId;PersonAttend;Result;Nextdt;Reminddt;Advname;"
          FormUpdateSQL1.DoVisible 4, False
          FormUpdateSQL1.DoVisible 6, False
          FormUpdateSQL1.DoVisible 8, False
          FormUpdateSQL1.AllowEdit = True
          FormUpdateSQL1.Refresh
          'cmbResult.Enabled = False
          cmbcaseId.Enabled = False
          cmbcourtid.Enabled = False
          cmbadvocateid.Enabled = False
          Call Grid_Data
      Exit Sub
      ChkErr:
      If Err.Number > 0 Then
      MsgBox Err.Number & vbNewLine & Err.Description
                 Call ErrHand("frmProceedings", "Form_Load")
          'Resume Next
      End If
      
      Grid_Data
      End Sub
      Private Sub cmbCaseId_Click()
      txtcaseid.Text = GetCorrespodingField("casemaster", "caseid", "CaseId", cmbcaseId, False)
      End Sub
      Private Sub cmbCaseId_GotFocus()
      Call fillcombo("casemaster", "CaseId", cmbcaseId, , True)
      End Sub
      Private Sub cmbCaseId_LostFocus()
      If cmbcaseId.Text = "" Then
          txtcaseid.Text = ""
      End If
      End Sub
      
      Private Sub txtCaseId_Change()
      'If txtparty.Text = "" Then
          cmbcaseId.Text = GetCorrespodingField("casemaster", "CaseId", "caseid", txtcaseid, False)
          'Call Grid_Data
         'End If
      End Sub
      Public Function fill()
          Dim Rs       As New ADODB.Recordset
          Dim i       As Integer
              
          If Rs.State = adStateOpen Then Rs.Close
              Rs.Open ("select Distinct proceedings.CaseId From proceedings, casemaster where casemaster.CaseId = '" & txtcaseid.Text & "' and proceedings.caseid = casemaster.caseid"), Db, adOpenKeyset, adLockPessimistic
              'select Distinct caseclaims.CaseId from CaseClaims,casemaster where casemaster.CaseId = '" & txtcaseid.Text & "' and caseclaims.caseid = casemaster.caseid"), Db, adOpenKeyset, adLockPessimistic
              ', MsVendors Ven,TxPoHdr Hdr Where Hdr.VendorId = '" & txtVendorId.Text & "' And Hdr.UnitId = Unit.UnitId and Hdr.YY = " & FinancialYear & " "), Db, adOpenKeyset, adLockPessimistic
         
          vCombo = ""
          cmbcaseId = ""
          cmbcaseId.Clear
          vCombo = cmbcaseId.Text
          
      '    If Clear Then Cmb.Clear
          i = 0
          While Not Rs.EOF
              If Rs.Fields(0) <> "" Then
                  cmbcaseId.AddItem Rs.Fields(0)
                  If Rs.Fields(0) = vCombo Then cmbcaseId.ListIndex = i
                  i = i + 1
              End If
              Rs.MoveNext
          Wend
          Rs.Close
          
      End Function
      
      Private Sub cmbCourtId_Click()
      Dim Rs       As New ADODB.Recordset
      txtcourtid.Text = GetCorrespodingField("court", "Courtid", "courtid", cmbcourtid, False)
      'Dim cn As String
      'Dim COURTID As Integer
      'If cmbCourtId.Text <> -1 Then
      'If Rs.State = adStateOpen Then Rs.Close
      'Rs.Open ("select courtname from court where courtid = '" & cmbCourtId.Text & "'"), Db, adOpenDynamic, adLockOptimistic
      'cn = Rs.Fields(COURTID).Value
      'Text1.Text = cn
      'Text1.Refresh
      'End If
      End Sub
      Private Sub cmbCourtId_GotFocus()
      Call fillcombo("casemaster", "CourtId", cmbcourtid, , True)
      End Sub
      Private Sub cmbCourtId_LostFocus()
      If cmbcourtid.Text = "" Then
          txtcourtid.Text = ""
      End If
      End Sub
      Private Sub txtCourtId_Change()
      'If txtCourtId.Text = "" Then
          cmbcourtid.Text = GetCorrespodingField("court", "CourtId", "CourtId", txtcourtid, False)
          'Call Grid_Data
         'End If
      End Sub
      Public Function fillCourtId()
          Dim Rs       As New ADODB.Recordset
          Dim i       As Integer
              
          If Rs.State = adStateOpen Then Rs.Close
              Rs.Open ("select Distinct proceedings.CourtId From proceedings, casemaster where casemaster.Courtid = '" & txtcourtid.Text & "' and casemaster.Courtid = proceedings.Courtid"), Db, adOpenKeyset, adLockPessimistic
              'select Distinct court.courtid from  court,casemaster,party where casemaster.PartyId = '" & txtpartyId.Text & "' And casemaster.courtid = court.courtid"), Db, adOpenKeyset, adLockPessimistic
              '"select Distinct courtid from  court,casemaster Where casemaster.partytype = '" & txtParty.Text & "'  And casemaster.courtid= court.courtid "), Db, adOpenKeyset, adLockPessimistic
         
          vCombo = ""
          cmbcourtid = ""
          cmbcourtid.Clear
          vCombo = cmbcourtid.Text
          
      '    If Clear Then Cmb.Clear
          i = 0
          While Not Rs.EOF
              If Rs.Fields(0) <> "" Then
                  cmbcourtid.AddItem Rs.Fields(0)
                  If Rs.Fields(0) = vCombo Then cmbcourtid.ListIndex = i
                  i = i + 1
              End If
              Rs.MoveNext
          Wend
          Rs.Close
      End Function
      Private Sub Form_KeyPress(KeyAscii As Integer)
      If KeyAscii = 13 Then
          SendKeys "{Tab}"
      End If
      End Sub
      Private Sub cmbAdvocateid_Click()
      Dim Rs       As New ADODB.Recordset
      txtadvocateid.Text = GetCorrespodingField("advocate", "advid", "advid", cmbadvocateid, False)
      Dim cn As String
      Dim advID As Integer
      If cmbadvocateid.Text <> -1 Then
      If Rs.State = adStateOpen Then Rs.Close
      Rs.Open ("select advname from advocate where advid = '" & cmbadvocateid.Text & "'"), Db, adOpenDynamic, adLockOptimistic
      cn = Rs.Fields(advID).Value
      txtadvocate.Text = cn
      txtadvocate.Refresh
      End If
      End Sub
      Private Sub cmbadvocateId_GotFocus()
      Call fillcombo("advocate", "advId", cmbadvocateid, , True)
      End Sub
      Private Sub cmbadvocateId_LostFocus()
      If cmbadvocateid.Text = "" Then
          txtadvocateid.Text = ""
      End If
      End Sub
      Private Sub txtadvocateId_Change()
      'If txtCourtId.Text = "" Then
          cmbadvocateid.Text = GetCorrespodingField("advocate", "advid", "advId", txtadvocateid, False)
          'Call Grid_Data
         'End If
      End Sub
      Public Function filladvocateId()
          Dim Rs       As New ADODB.Recordset
          Dim i       As Integer
              
          If Rs.State = adStateOpen Then Rs.Close
              Rs.Open ("select Distinct advocate.advId From advocate,proceedings where proceedings.advid = '" & txtadvocateid.Text & "' and advocate.advid = proceedings.advid"), Db, adOpenKeyset, adLockPessimistic
              'select Distinct court.courtid from  court,casemaster,party where casemaster.PartyId = '" & txtpartyId.Text & "' And casemaster.courtid = court.courtid"), Db, adOpenKeyset, adLockPessimistic
              '"select Distinct courtid from  court,casemaster Where casemaster.partytype = '" & txtParty.Text & "'  And casemaster.courtid= court.courtid "), Db, adOpenKeyset, adLockPessimistic
         
          vCombo = ""
          cmbadvocateid = ""
          cmbadvocateid.Clear
          vCombo = cmbadvocateid.Text
          
      '    If Clear Then Cmb.Clear
          i = 0
          While Not Rs.EOF
              If Rs.Fields(0) <> "" Then
                  cmbadvocateid.AddItem Rs.Fields(0)
                  If Rs.Fields(0) = vCombo Then cmbadvocateid.ListIndex = i
                  i = i + 1
              End If
              Rs.MoveNext
          Wend
          Rs.Close
      End Function
      Public Sub Grid_Data()
      On Error GoTo ChkErr
          Adodc1.ConnectionString = pStrConnectionString
          Adodc1.RecordSource = "Select ID,Description,CourtId,CaseId as CaseNo,AdvId,Advname as AdvocateName,PersonAttend,Result,convert(varchar(20),Proceedings.Nextdt,6) as NextDate,convert(VarChar(20), Proceedings.Reminddt, 6) As RemindDate From Proceedings"
          Adodc1.Refresh
          Set MSHFlexGrid1.DataSource = Adodc1
          Set MSHFlexGrid1.Recordset = Adodc1.Recordset
          Adodc1.Refresh
          MSHFlexGrid1.ColWidth(1) = 800
          MSHFlexGrid1.ColWidth(2) = 3000
          MSHFlexGrid1.ColWidth(3) = 1000
          MSHFlexGrid1.ColWidth(4) = 800
          MSHFlexGrid1.ColWidth(5) = 800
          MSHFlexGrid1.ColWidth(6) = 2000
          MSHFlexGrid1.ColWidth(7) = 2000
          MSHFlexGrid1.ColWidth(8) = 1500
          MSHFlexGrid1.ColWidth(9) = 1500
          MSHFlexGrid1.ColWidth(10) = 1500
          MSHFlexGrid1.Refresh
      Exit Sub
      ChkErr:
      If Err.Number > 0 Then
      MsgBox Err.Number & vbNewLine & Err.Description
                 Call ErrHand("frmProceedings", "Grid_Data")
          'Resume Next
      End If
      End Sub
      
      Private Sub FormUpdateSQL1_AddClick()
      DTPnextdt.Value = Date
      DTPReminddt.Value = Date
      cmbcaseId.Enabled = True
      cmbcourtid.Enabled = True
      cmbadvocateid.Enabled = True
      cmbResult.Enabled = True
      cmbResult.Enabled = True
      txtId.Text = GetNextCode("Proceedings", "ID")
      'txtAdvocateId.Text = GetNextCode("Advocate", "AdvID")
      'cmbResult.Enabled = True
      txtId.Enabled = False
      'cmbResult.Enabled = True
      'txtAdvocateId.Enabled = False
      'ChkInd.Value = 1
      End Sub
      
      Private Sub FormUpdateSQL1_AfterControlsEnabled()
      'FormUpdateSQL1.DoVisible 5, False
      'FormUpdateSQL1.DoVisible 1, False
      cmbcaseId.Enabled = True
      cmbResult.Enabled = True
      cmbcourtid.Enabled = True
      cmbadvocateid.Enabled = True
      End Sub
      
      Private Sub FormUpdateSQL1_AfterUpdate()
      cmbResult.Enabled = True
      cmbcaseId.Enabled = True
      cmbcourtid.Enabled = True
      cmbadvocateid.Enabled = True
      Call Grid_Data
      End Sub
      [B]
      Private Sub FormUpdateSQL1_BeforeValidate()
      If cmbResult.Text = "" Then
      MsgBox " Enter the particular result"
      cmbResult.SetFocus
      FormUpdateSQL1.CancelEvent = True
      End If
      Exit Sub
      FormUpdateSQL1.CancelEvent = True
      End Sub[/B]
      
      
      Private Sub MSHFlexGrid1_DblClick()
      FormUpdateSQL1.ViewRecord True, Val(MSHFlexGrid1.Text)
      End Sub

      Comment

      • squrel
        New Member
        • Jan 2008
        • 143

        #4
        Is anyone can help me here? i have past the full code tht i m working on it
        thank u

        Comment

        • debasisdas
          Recognized Expert Expert
          • Dec 2006
          • 8119

          #5
          Originally posted by squrel
          i have past the full code tht i m working on it
          thats why noone is looking at them.

          when you post the code ,do not post all the code you have.

          just post the part that you are facing problem with.---i hope that makes sence

          Comment

          • squrel
            New Member
            • Jan 2008
            • 143

            #6
            Hi..
            i m very sorry bt u told me to send the code tht i m working on it.. thts why i send the whole code of tht form... ok my problem is this part... i have setfocus here bt my combo box content still getting repeted.. i have filled my combo box from the properties.. am i missing something? wil u plz look at this part and let me knw..
            thanks a lot


            Code:
            Private Sub FormUpdateSQL1_BeforeValidate()
            If cmbResult.Text = "" Then
            MsgBox " Enter the particular result"
            cmbResult.SetFocus
            FormUpdateSQL1.CancelEvent = True
            End If
            Exit Sub
            FormUpdateSQL1.CancelEvent = True
             End Sub

            Comment

            Working...