User formda çift kayıdı engellemek için ne yapmalıyım?
Userformdaki kodlarım bunlar.
Ayrıca Sheet2 sayfasında kontrol yaparken barkodu bulamazsa kod hatası veriyor. Bunun içinde yardımcı olabilir misiniz?
Private Sub CmdCheck_Click()
'Check to see if value exitsts
If Application.WorksheetFunction.CountIf(Sheet2.Range("B:B"), Me.Reg1.Value) = 0 Then
Me.Reg1.Value = ""
MsgBox "The Barcode Invalid!!!"
Exit Sub
End If
'Lookup values based on first control
With Me
.Reg2 = Application.WorksheetFunction.VLookup(CStr(Me.Reg1), Sheet2.Range("Lookup"), 2, 0)
.Reg3 = Application.WorksheetFunction.VLookup(CStr(Me.Reg1), Sheet2.Range("Lookup"), 3, 0)
.Reg4 = Application.WorksheetFunction.VLookup(CStr(Me.Reg1), Sheet2.Range("Lookup"), 4, 0)
.Reg5 = Application.WorksheetFunction.VLookup(CStr(Me.Reg1), Sheet2.Range("Lookup"), 5, 0)
.Reg6 = Application.WorksheetFunction.VLookup(CStr(Me.Reg1), Sheet2.Range("Lookup"), 6, 0)
.Reg7 = Application.WorksheetFunction.VLookup(CStr(Me.Reg1), Sheet2.Range("Lookup"), 7, 0)
MsgBox " The Barcode have not exitsted!!"
End With
End Sub
Private Sub CmdClose_Click()
'Close the UserForm1
Unload Me
End Sub
Private Sub Cmdd_Click()
'Check to see if value exitsts
If Application.WorksheetFunction.CountIf(Sheet2.Range("B:B"), Me.Reg1.Value) > 1 Then
Me.Reg1.Value = ""
MsgBox "The Barcode Already Exitsted!!!"
Exit Sub
End If
'Dim the variables
Dim cNum As Integer
Dim x As Integer
Dim nextrow As Range
'change the number for the number of controls on the userform
cNum = 8
Set nextrow = Sheet2.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
For x = 1 To cNum
nextrow = Me.Controls("Reg" & x).Value
Set nextrow = nextrow.Offset(0, 1)
Next
MsgBox "Data Submitted"
'Clear the controls
cNum = 8
For x = 1 To cNum
Me.Controls("Reg" & x).Value = ""
Set nextrow = nextrow.Offset(0, 1)
Next
End Sub
Userformdaki kodlarım bunlar.
Ayrıca Sheet2 sayfasında kontrol yaparken barkodu bulamazsa kod hatası veriyor. Bunun içinde yardımcı olabilir misiniz?
Private Sub CmdCheck_Click()
'Check to see if value exitsts
If Application.WorksheetFunction.CountIf(Sheet2.Range("B:B"), Me.Reg1.Value) = 0 Then
Me.Reg1.Value = ""
MsgBox "The Barcode Invalid!!!"
Exit Sub
End If
'Lookup values based on first control
With Me
.Reg2 = Application.WorksheetFunction.VLookup(CStr(Me.Reg1), Sheet2.Range("Lookup"), 2, 0)
.Reg3 = Application.WorksheetFunction.VLookup(CStr(Me.Reg1), Sheet2.Range("Lookup"), 3, 0)
.Reg4 = Application.WorksheetFunction.VLookup(CStr(Me.Reg1), Sheet2.Range("Lookup"), 4, 0)
.Reg5 = Application.WorksheetFunction.VLookup(CStr(Me.Reg1), Sheet2.Range("Lookup"), 5, 0)
.Reg6 = Application.WorksheetFunction.VLookup(CStr(Me.Reg1), Sheet2.Range("Lookup"), 6, 0)
.Reg7 = Application.WorksheetFunction.VLookup(CStr(Me.Reg1), Sheet2.Range("Lookup"), 7, 0)
MsgBox " The Barcode have not exitsted!!"
End With
End Sub
Private Sub CmdClose_Click()
'Close the UserForm1
Unload Me
End Sub
Private Sub Cmdd_Click()
'Check to see if value exitsts
If Application.WorksheetFunction.CountIf(Sheet2.Range("B:B"), Me.Reg1.Value) > 1 Then
Me.Reg1.Value = ""
MsgBox "The Barcode Already Exitsted!!!"
Exit Sub
End If
'Dim the variables
Dim cNum As Integer
Dim x As Integer
Dim nextrow As Range
'change the number for the number of controls on the userform
cNum = 8
Set nextrow = Sheet2.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
For x = 1 To cNum
nextrow = Me.Controls("Reg" & x).Value
Set nextrow = nextrow.Offset(0, 1)
Next
MsgBox "Data Submitted"
'Clear the controls
cNum = 8
For x = 1 To cNum
Me.Controls("Reg" & x).Value = ""
Set nextrow = nextrow.Offset(0, 1)
Next
End Sub