ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,975
- Office Version
- 2007
- Platform
- Windows
Morning all,
The supplied code below i believe is what you require & is currently in use BUT i would like an extra piece of code added to it if i may ask please.
This is how it currently works,
I select ADD NEW CUSTOMER TO DATABASE & complete all fields.
I then select SAVE NEW CUSTOMER TO DATABASE,this then saves the data into my worksheet.
This currently works fine.
The extra piece of code i require is as follows,
Once all the fields are completed & SAVE NEW CUSTOMER TO DATABASE is selected BEFORE it is saved to the worksheet check column A to see if there is a match.
The two items that need to be checked would be Customers name on user form & Customers name which is in Column A on my worksheet.
It would work something like this,
If no match is found then allow the save to go ahead,which is what currently happens.
If there is a match then maybe have message box appear saying customer exists etc.
Allow me to then edit that customers name on the user form etc and then be able to select SAVE NEW CUSTOMER TO DATABASE for the save to go ahead.
This will then allow me NOT to have duplicated customers names in my worksheet.
Check should allow upper case / lower case check and not be 100% specific match etc, Dave Tomms / DAVE TOMMS etc etc
Many thanks & hope i have not over explained it ?
The supplied code below i believe is what you require & is currently in use BUT i would like an extra piece of code added to it if i may ask please.
This is how it currently works,
I select ADD NEW CUSTOMER TO DATABASE & complete all fields.
I then select SAVE NEW CUSTOMER TO DATABASE,this then saves the data into my worksheet.
This currently works fine.
The extra piece of code i require is as follows,
Once all the fields are completed & SAVE NEW CUSTOMER TO DATABASE is selected BEFORE it is saved to the worksheet check column A to see if there is a match.
The two items that need to be checked would be Customers name on user form & Customers name which is in Column A on my worksheet.
It would work something like this,
If no match is found then allow the save to go ahead,which is what currently happens.
If there is a match then maybe have message box appear saying customer exists etc.
Allow me to then edit that customers name on the user form etc and then be able to select SAVE NEW CUSTOMER TO DATABASE for the save to go ahead.
This will then allow me NOT to have duplicated customers names in my worksheet.
Check should allow upper case / lower case check and not be 100% specific match etc, Dave Tomms / DAVE TOMMS etc etc
Many thanks & hope i have not over explained it ?
Code:
Private Sub UpdateRecord_Click() Dim i As Integer
Dim IsNewCustomer As Boolean
Dim Msg As String
IsNewCustomer = CBool(Me.UpdateRecord.Tag)
Msg = "CHANGES SAVED SUCCESSFULLY"
If IsNewCustomer Then
'New record - check all fields entered
If Not IsComplete(Form:=Me) Then Exit Sub
r = StartRow
Msg = "NEW CUSTOMER SAVED TO DATABASE"
ws.Range("A6").EntireRow.Insert
ResetButtons Not IsNewCustomer
Me.NextRecord.Enabled = True
End If
On Error GoTo myerror
Application.EnableEvents = False
'Add / Update Record
For i = 1 To UBound(ControlNames)
With Me.Controls(ControlNames(i))
'check if date value
If IsDate(.Text) Then
ws.Cells(r, i).Value = DateValue(.Text)
ElseIf i = 15 Then
ws.Cells(r, i).Value = CDbl(.Text)
Else
ws.Cells(r, i).Value = UCase(.Text)
End If
ws.Cells(r, i).Font.Size = 11
End With
Next i
If IsNewCustomer Then Call ComboBoxCustomersNames_Update
ThisWorkbook.Save
'tell user what happened
MsgBox Msg, 48, Msg
myerror:
Application.EnableEvents = True
'something went wrong tell user
If Err > 0 Then MsgBox (Error(Err)), 48, "Error"
End Sub
Sub ResetButtons(ByVal Status As Boolean)
With Me.NewRecord
.Caption = IIf(Status, "CANCEL", "ADD NEW CUSTOMER TO DATABASE")
.BackColor = IIf(Status, &HFF&, &H8000000F)
.ForeColor = IIf(Status, &HFFFFFF, &H0&)
.Tag = Not Status
Me.ComboBoxCustomersNames.Enabled = CBool(.Tag)
End With
With Me.UpdateRecord
.Caption = IIf(Status, "SAVE NEW CUSTOMER TO DATABASE", "SAVE CHANGES FOR THIS CUSTOMER")
.Tag = Status
End With
End Sub
Last edited: