USERFORM: DELETE command & correct code of EDIT/AMEND?

srands

Board Regular
Joined
Jun 24, 2010
Messages
115
Made a great USERFORM database, current features are good including SEARCH/EDIT RECORD & ADD, however VB code edits needed:

http://www.1sar.karoo.net/DB~ADD,EDIT&SEARCHcars.xls 248 KB's

HOW TO CORRECT or CREATE THE FOLLOWING FEATURES: :ROFLMAO:

i). AMEND records feature, causes a DOUBLE ENTRY overwriting existing data in the "database" spreadsheet. WHY & HOW to correct this code? :confused:

ii). USERFORM needs DELETE RECORD feature, possibly from with search feature, button next to AMEND SELECTION perhaps. :rolleyes:

iii). USERFORM needs BROWSE through RECORDS feature using NEXT & PREVIOUS BUTTONS would be a useful additional, whilst in SEARCH feature via SEARCH/EDIT RECORD. :)
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
You'll have better luck actually posting the code, as many people are blocked from external file sharing sites, or simply choose not to download files from untrusted sources.
 
Upvote 0
Ok, the hyperlinks work currently, I'd would have attached the file in the first place however the file size is greater then most xl forum allowed max attachment file size. Anyway as aforementioned the code needs editing for USERFORM3, below here is the VB code:
i). AMEND records feature, causes a DOUBLE ENTRY overwriting existing data in the "database" spreadsheet. WHY & HOW to correct this code? :confused:
ii). USERFORM needs DELETE RECORD feature, possibly from with search feature, button next to AMEND SELECTION perhaps. :rolleyes:
iii). USERFORM needs BROWSE through RECORDS feature using NEXT & PREVIOUS BUTTONS would be a useful additional, whilst in SEARCH feature via SEARCH/EDIT RECORD. :)

Code:
Dim Rw As Long
Dim Cap As IntegerSub HighLight1(Ctrl As Control)
    With Ctrl
        If .Value = True Then
            .BackColor = RGB(255, 255, 0)
        Else
            .BackColor = vbButtonFace
        End If
    End With
End Sub
Sub HighLight2(Ctrl As Control)
    With Ctrl
        If .Value = True Then
            .BackColor = RGB(0, 255, 255)
        Else
            .BackColor = vbButtonFace
        End If
    End With
End Sub
Private Sub CheckBox1_Change()
    HighLight2 CheckBox1
End Sub
Private Sub CheckBox2_Click()
    HighLight2 CheckBox2
End Sub
Private Sub CheckBox3_Click()
    HighLight2 CheckBox3
End Sub
Private Sub cmdAmend_Click()
Dim DataRw As Long
For Cap = 1 To 28
DataRw = Sheet5.Cells(Rw, 29).Value
Sheet1.Cells(Rw, Cap).Value = Me("tbx" & Cap).Value
Next Cap
End Sub
Private Sub CommandButton1_Click()
'SEARCH
    Dim C As Variant
    Dim Col As Variant
    Dim Ctrl As Object
    Dim Data As Variant
    Dim DstWks As Worksheet
    Dim BtnNumber As Integer
    Dim FirstAddx As String
    Dim FoundIt As Range
    Dim i As Integer
    Dim R As Long
    Dim rng As Range
    Dim RngEnd As Range
    Dim SrcWks As Worksheet
    Set SrcWks = Worksheets("Data")
    Set DstWks = Worksheets("Search Details")
    With Frame1.Controls
        For i = 0 To .Count - 1
            If .Item(i).Value = True Then
                BtnName = .Item(i).Name
                Exit For
            End If
        Next i
    End With
    Select Case BtnName
    Case "OptionButton1"
        Col = 1: Data = TextBox1: GoSub DataSearch
        Col = 2: Data = TextBox2: GoSub DataSearch
    Case "OptionButton2"
        Col = 3: Data = TextBox1: GoSub DataSearch
    Case "OptionButton3"
        Col = 4: Data = TextBox2: GoSub DataSearch
    Case "OptionButton4"
        Col = 18: Data = TextBox2: GoSub DataSearch
    End Select
    Exit Sub
DataSearch:
    With DstWks
        Set RngEnd = .Cells.Find("*", [A1], xlFormulas, xlWhole, xlByRows, xlPrevious, False)
        R = RngEnd.Row
        R = IIf(R < 2, 2, R + 1)
    End With
    With SrcWks
        Set rng = .Cells(2, Col)
        Set RngEnd = .Cells(Rows.Count, Col).End(xlUp)
        Set RngEnd = IIf(RngEnd.Row < rng.Row, rng, RngEnd)
        Set rng = .Range(rng, RngEnd)
    End With
    Data = Trim(Data)
    Set FoundIt = rng.Find(What:=Data, After:=rng.Cells(1, 1), _
                           LookIn:=xlFormulas, LookAt:=CheckBox2.Value + 2, _
                           SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                           MatchCase:=CheckBox1.Value)
    If Not FoundIt Is Nothing Then
        FirstAddx = FoundIt.Address
        FoundIt.EntireRow.Resize(1, 28).Copy Destination:=DstWks.Cells(R, 1)
        If CheckBox3.Value = False Then Exit Sub
        Do
                DstWks.Cells(R, 29).Value = FoundIt.Row
            FoundIt.EntireRow.Resize(1, 28).Copy Destination:=DstWks.Cells(R, 1)
            Set FoundIt = rng.FindNext(FoundIt)
            R = R + 1
        Loop While FoundIt.Address <> FirstAddx And Not FoundIt Is Nothing
        Me.ListBox1.RowSource = DstWks.UsedRange.Address(external:=True)
        Me.Height = 425  ' 391
    Else
        MsgBox "No Match was found for '" & Data & " '", vbExclamation
    End If
End Sub
Private Sub CommandButton2_Click()
'CLOSE
    Me.Hide
    Unload Me
End Sub
Private Sub CommandButton3_Click()
'RESET FORM
    TextBox1.Value = ""
    TextBox2.Value = ""
    OptionButton1.Value = True
    CheckBox1.Value = False
    CheckBox2.Value = False
    CheckBox3.Value = True
    TextBox1.SetFocus
End Sub
Private Sub CommandButton4_Click()
Dim tbl As Range
Dim Answer As String
    Answer = MsgBox("This will remove any searches you have already done." & vbCrLf _
                  & "Are you sure you want to clear Search Details?", vbQuestion + vbYesNo)
    If Answer = vbYes Then
    Set tbl = Worksheets("Search Details").Range("A2").CurrentRegion
 tbl.Offset(1, 0).Resize(tbl.Rows.Count - 1, _
    tbl.Columns.Count).ClearContents
    End If
End Sub
Private Sub ListBox1_Click()
Rw = Me.ListBox1.ListIndex + 1
With Me
.Width = 750    ' 548
    For Cap = 1 To 28
    Me("lbl" & Cap).Caption = Sheet5.Cells(1, Cap).Value
    Me("tbx" & Cap).Value = Sheet5.Cells(Rw, Cap).Value
    Next Cap
    End With
End Sub
Private Sub OptionButton1_Change()
    HighLight1 OptionButton1
End Sub
Private Sub OptionButton1_Click()
    If OptionButton1.Value = True Then
        Label1.Caption = "Car Manufacturer"
        TextBox1.Visible = True
        Label2.Caption = "Car Model"
        TextBox2.Visible = True
        TextBox1.SetFocus
    End If
End Sub
Private Sub OptionButton2_Change()
    HighLight1 OptionButton2
End Sub
Private Sub OptionButton2_Click()
    If OptionButton2.Value = True Then
        Label1.Caption = "Model Type"
        TextBox1.Visible = True
        Label2.Caption = ""
        TextBox2.Visible = False
        TextBox1.SetFocus
    End If
End Sub
Private Sub OptionButton3_Change()
    HighLight1 OptionButton3
End Sub
Private Sub OptionButton3_Click()
    If OptionButton3.Value = True Then
        Label1.Caption = ""
        TextBox1.Visible = False
        Label2.Caption = "Litre"
        TextBox2.Visible = True
        TextBox2.SetFocus
    End If
End Sub
Private Sub OptionButton4_Change()
    HighLight1 OptionButton4
End Sub
Private Sub OptionButton4_Click()
    If OptionButton4.Value = True Then
        Label1.Caption = ""
        TextBox1.Visible = False
        Label2.Caption = "Colour"
        TextBox2.Visible = True
        TextBox2.SetFocus
    End If
End Sub
Private Sub UserForm_Activate()
Me.CommandButton3.Value = True
End Sub
Private Sub UserForm_Initialize()
Me.Height = 220
Me.Width = 384
End Sub
 
Upvote 0

The only problem with that, being an ADD-IN, then XL files that rely on this feature I presume would not function correctly on other PC's with EXCEL, without the ADD-IN.

Hence instead will continue to use COMMAND BUTTONS/USERFORM/VB CODE, easier to edit as well.

VB code is not something I do often as I don't work in an office, I look for obvious references for rows/columns then edit them to my own needs. After all FORMULAs are relatively well defined in terms of commands and ranges, however VB code a blank page, hence I look at examples, find some good ones and copy & paste relevant userforms/vb code.
 
Upvote 0
pay fee for source code add-in. Here's another source New Improved Excel Data Entry Form | Contextures Blog

Hi, really looking for an edit for my USERFORM, or another USERFORM that can be edited easily.

The contextures isn't really a USERFORM solution, but the easiest to use/edit, and I've already done it to my examples:
DB COMBO SEARCH A-Z consecutive, ADD/EDIT/BROWSE & SEARCH inc PHOTO

See 3 HYPERLINKS following, an amalgamation of some great ideas :eek::
~ COMBO BOX SEARCH which display PHOTOS on a separate tab called RESULTS.
~ ADD/UPDATE/DELETE/BROWSE/SEARCH records which automatically display available photos on a separate tab called INPUT.
These spreadsheets are populated with example list of cars, but the data can be replaced by whatever, here are the 3 different types:


i). COMBO SEARCH A-Z CONSECUTIVE VERTICAL BAR with 4 CATEGORIES R/H of screen with PHOTOS: File Size 1 MB
http://www.1sar.karoo.net/exoftable3...editDELETE.xls

ii). COMBO SEARCH A-Z CONSECUTIVE HORIZONTAL BAR with 4 CATEGORIES TOP of screen: File Size 1 MB
http://www.1sar.karoo.net/exoftable3...editDELETE.xls

iii). COMBO SEARCH A-Z CONSECUTIVE HORIZONTAL BAR with 11 CATEGORIES TOP of screen: File Size 1 MB
http://www.1sar.karoo.net/exoftable3...editDELETE.xls
 
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,168
Members
448,870
Latest member
max_pedreira

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top