I have a Userform full of textboxes which allows users to enter information into a database.
the code below allows me to do this, however if i want to make e.g. the txtID and txtName unique, so that no other fields in the database can contain these. How would i go about doing this?
the code below allows me to do this, however if i want to make e.g. the txtID and txtName unique, so that no other fields in the database can contain these. How would i go about doing this?
VBA Code:
Sub Submit()
'code for submitting data to database
Dim sh As Worksheet
Dim iRow As Long
Set sh = ThisWorkbook.Sheets("Database")
If frmForm.txtRowNumber.Value = "" Then
iRow = [Counta(Database!A:A)] + 1
Else
iRow = frmForm.txtRowNumber.Value
End If
With sh
'adding each row to database
.Cells(iRow, 1) = "=Row()-1" 'Dynamic Serial Number
.Cells(iRow, 2) = frmForm.ComboBox1.Value
.Cells(iRow, 3) = frmForm.txtName.Value
.Cells(iRow, 4) = frmForm.txtID.Value
.Cells(iRow, 5) = frmForm.txtCity.Value
.Cells(iRow, 6) = frmForm.TextBox1.Value
.Cells(iRow, 7) = frmForm.TextBox4.Value
.Cells(iRow, 8) = frmForm.TextBox5.Value