Results 1 to 6 of 6

Thread: [RESOLVED] how to prevent that at the input to the msflexgrid not duplicate

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Posts
    22

    Resolved [RESOLVED] how to prevent that at the input to the msflexgrid not duplicate

    hello all
    i have problem to prevent that at the input to the grid not duplicate

    this is my form


    in my form there is duplicate data

    this is my coding insert data from textbox to msflexgrid
    Code:
    Private Sub Command2_Click()
    If Text2.Text = "" Then
    MsgBox "Kode Voucher Masih Kosong !", vbOKOnly + vbCritical, "KONFIRMASI"
    Command1.SetFocus
        ElseIf Val(Text8.Text) > Val(Text5.Text) Then
            MsgBox " Stok Voucher Tidak Memadai !", vbOKOnly + vbCritical, "KONFIRMASI"
        ElseIf Gridtransaksi.Rows = 1 Then
            MsgBox "Belum Ada Voucher Yang Akan Dijual !", vbOKOnly + vbCritical, "KONFIRMASI"
        Else
            With Gridtransaksi
                .Rows = baris + 1
                .TextMatrix(baris, 0) = Text2.Text
                .TextMatrix(baris, 1) = Text3.Text
                .TextMatrix(baris, 2) = Text4.Text
                .TextMatrix(baris, 3) = Text8.Text
                .TextMatrix(baris, 4) = Text6.Text
            End With
                Call Total
                baris = baris + 1
                Call bersihvoucher
            End If
    End Sub
    is there any idea to solve my problem ?

    Thanks

    Andi

    Regard's

  2. #2
    Frenzied Member
    Join Date
    May 2013
    Posts
    1,126

    Re: how to prevent that at the input to the msflexgrid not duplicate

    you may want to loop in the column of your grid that you want only nique record and compare it to something, so if there is a result in your loop, then you have already an existing record else otherwise.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Posts
    22

    Re: how to prevent that at the input to the msflexgrid not duplicate

    Can you give me an example
    How to do it ?

    Thanks

    Andi

    regard's

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: how to prevent that at the input to the msflexgrid not duplicate

    What do you want to prevent duplication of? Kode? Does it matter if the OTHER columns may be the same?

    If it is Kode, then do this:

    Code:
    Private Sub Command2_Click()
        Dim baris As Integer
        baris = Gridtransaksi.Rows
        Dim x As Integer
        If Text2.Text = "" Then
        MsgBox "Kode Voucher Masih Kosong !", vbOKOnly + vbCritical, "KONFIRMASI"
        Command1.SetFocus
        Else
            For x = 1 To Gridtransaksi.Rows - 1
                If Gridtransaksi.TextMatrix(x, 0) = Text2.Text Then
                    MsgBox "Kode already exists!", vbCritical
                    Exit Sub
                End If
            Next x
    
            With Gridtransaksi
                .Rows = baris + 1
                .TextMatrix(baris, 0) = Text2.Text
                .TextMatrix(baris, 1) = Text3.Text
                .TextMatrix(baris, 2) = Text4.Text
                .TextMatrix(baris, 3) = Text8.Text
                .TextMatrix(baris, 4) = Text6.Text
            End With
                Call Total
                baris = baris + 1
                Call bersihvoucher
            End If
    End Sub

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2015
    Posts
    22

    Re: how to prevent that at the input to the msflexgrid not duplicate

    thanks a lot for your help

    Andi

    regard's

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: [RESOLVED] how to prevent that at the input to the msflexgrid not duplicate

    Here...I did a bit more for you.....might help as you try to type in new voucher numbers...finds largest number in your grid and adds 1 to it if you want to do that.



    Attachment 127851

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width