Hello to all ,
I am posting here for the first time. i am from Germany, please forgive my bad English. I have the following problem:
I have a userform. The data is then inserted into the table via Public Function Data_Write (Code below). This works also perfectly.
How can I prevent duplicate data records from being entered? I want to check for duplicates before writing to the table. I want to check ALL columns.
I want to use "check if duplicate" also for other forms, so write it in a function.
If the data is already available, a message should appear "New Data are written". If data has been changed, only the change should be saved an a message should appear "data were changed".
Does anyone have a suggestion for me how I could realize this?
Many thanks for the support.
See my Function Code Data_Write
'Call from the respective form via button OK
'Transfer table name and form name
'In the form the tab Userform Tag must be set so that the columns are written continuously
'--------------------------------------------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------------------------------------
Sub Write_Data(wkstab As Worksheet, UFName As Object)
Dim objControl As Control 'all controls from the userform
Dim FirstEmtyRow As Long 'For first empty row in descriptive table
Dim i As Long 'loop counter for column entry
FirstEmtyRow = wkstab.UsedRange.Rows.Count + 1 'Set first free line in the used area
For Each objControl In UFName.Controls
If IsNumeric(objControl.Tag) Then 'If the ControlTag is numeric then entry in olumn
wkstab.Cells(FirstEmtyRow, objControl.TabIndex + 1) = objControl.value
End If
Next objControl
End Sub
I am posting here for the first time. i am from Germany, please forgive my bad English. I have the following problem:
I have a userform. The data is then inserted into the table via Public Function Data_Write (Code below). This works also perfectly.
How can I prevent duplicate data records from being entered? I want to check for duplicates before writing to the table. I want to check ALL columns.
I want to use "check if duplicate" also for other forms, so write it in a function.
If the data is already available, a message should appear "New Data are written". If data has been changed, only the change should be saved an a message should appear "data were changed".
Does anyone have a suggestion for me how I could realize this?
Many thanks for the support.
See my Function Code Data_Write
'Call from the respective form via button OK
'Transfer table name and form name
'In the form the tab Userform Tag must be set so that the columns are written continuously
'--------------------------------------------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------------------------------------
Sub Write_Data(wkstab As Worksheet, UFName As Object)
Dim objControl As Control 'all controls from the userform
Dim FirstEmtyRow As Long 'For first empty row in descriptive table
Dim i As Long 'loop counter for column entry
FirstEmtyRow = wkstab.UsedRange.Rows.Count + 1 'Set first free line in the used area
For Each objControl In UFName.Controls
If IsNumeric(objControl.Tag) Then 'If the ControlTag is numeric then entry in olumn
wkstab.Cells(FirstEmtyRow, objControl.TabIndex + 1) = objControl.value
End If
Next objControl
End Sub