I have a sheet with several rows that heve been populated from a form, togheter with a checkbox in column A.
If the user tries to filter the data by different criteria, and forgets to turn it off. He will get problems the next time he tries to add a record from the form. The checkbox will not be inserted, but the text from the form is saved correct.
So is there a way to get the checkbox inserted even if the filter is on?
Private Sub cmdAdd_Click()Dim lRow As LongDim lKunde As LongDim ws As WorksheetDim obj As ObjectSet ws = Worksheets("Timer til fakturering")'find first empty row in databaselRow = ws.Cells(Rows.Count, 1) _ .End(xlUp).Offset(1, 0).RowlKunde = Me.cboKunde.ListIndex'check for a "kunde" numberIf Trim(Me.cboKunde.Value) = "" Then Me.cboKunde.SetFocus MsgBox "Vennligst skriv inn kunde" Exit SubEnd If'Set in checkboxWith ws Set obj = .OLEObjects.Add(ClassType:="Forms.CheckBox.1", Link:=False, _ DisplayAsIcon:=False, Left:=.Cells(lRow, 1).Left + 10, Top:=.Cells(lRow, 1).Top + 3, Width:=49, Height:=16) obj.Object.Caption = "Fakturer" obj.LinkedCell = Cells(lRow, 1).Address obj.Object.Value = FalseEnd With'copy the data to the databaseWith ws .Cells(lRow, 2).Value = Me.cboKunde.Value .Cells(lRow, 3).Value = Me.txtKontakt.Value .Cells(lRow, 4).Value = Me.cboAktivitet.Value .Cells(lRow, 5).Value = CDate(frmTime.txtDate.Value) .Cells(lRow, 6).Value = Me.txtQty.Value .Cells(lRow, 7).Value = Me.txtPris.Value .Cells(lRow, 8).Value = Me.txtFastpris.Value .Cells(lRow, 9).Value = Format$(frmTime.SumTotal.Value) .Cells(lRow, 10).Value = Me.txtAntKm.Value .Cells(lRow, 11).Value = Me.txtSats.Value .Cells(lRow, 12).Value = Format$(frmTime.txtSumtravel.Value) .Cells(lRow, 13).Value = Me.txtOvertid.Value 'Use Caption with labels, value will not work .Cells(lRow, 14).Value = Me.LabelUser.CaptionEnd With'clear the dataMe.cboKunde.Value = ""Me.txtKontakt.Value = ""Me.cboAktivitet.Value = ""Me.txtDate.Value = Format(Date, "Medium Date")Me.txtPris.Value = ""Me.txtQty.Value = 1Me.txtTotal.Value = ""Me.txtFastpris.Value = ""Me.txtAntKm.Value = ""Me.txtSats.Value = "3.5"Me.txtTotTravel.Value = ""Me.txtOvertid.Value = ""Me.cboKunde.SetFocusEnd Sub
How about not using checkboxes in the first place?
You could use Data>Validation to provide a Yes/No dropdown for each row of data, you can even set the font to display a tick/cross.
Each time you add a new record to the spreadsheet you can just copy the data validation to the appropriate column.
By the way you could clear the userform by just closing it and opening it again, adding some code in the initialize event to set any defaults.
Private Sub cmdAdd_Click()... code to add new record' close form and reopenUnload MeUserForm1.Show ' change name to that of the user formEnd SubPrivate Sub UserForm_Initialize()' code for defaultsMe.txtDate.Value = Format(Date, "Medium Date") Me.txtQty.Value = 1 Me.txtSats.Value = "3.5" End Sub
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
You could use Data>Validation to provide a Yes/No dropdown for each row of data, you can even set the font to display a tick/cross.
Each time you add a new record to the spreadsheet you can just copy the data validation to the appropriate column.
By the way you could clear the userform by just closing it and opening it again, adding some code in the initialize event to set any defaults.
Open in new window