Multi records delete (1 Viewer)

Gasman

Enthusiastic Amateur
Local time
Today, 05:18
Joined
Sep 21, 2011
Messages
14,533
Start walking through the code with F8 then.
Set a breakpoint in the start of that form and take it from there.

Probably this code. You set boolean controls to True/False, not non boolean controls. :(
False is value 0 ? True is -1
Code:
txtStartDate.Value = False
txtEndDate.Value = False
You also do not need the .Value, that is the default property, but if you are more comfortable using it, then do so.
 

mikekal

Member
Local time
, 21:18
Joined
Jun 24, 2017
Messages
114
Can you give me an example to filter records.I want to filter :date from --- date to and filter with combobox
 

Gasman

Enthusiastic Amateur
Local time
Today, 05:18
Joined
Sep 21, 2011
Messages
14,533
Put this at the top of a module
Code:
Public Const strcJetDate = "\#mm\/dd\/yyyy\#"  'Needed for dates in queries as Access expects USA format.

then where you want your filter
Code:
Me.Filter = "MyDate BETWEEN " & Format(Me.FromDate,strcJetDate ) & " AND " & Format(Me.ToDate,strcJetDate )

Not sure how you can use a combo, as you need two dates?

You also need to start googling for stuff like this. Plenty of examples out there. That way you learn, not just take code and paste.
 

mikekal

Member
Local time
, 21:18
Joined
Jun 24, 2017
Messages
114
My code on filter is:

Private Sub cmdFilter_Click()
'Purpose: Build up the criteria string form the non-blank search boxes, and apply to the form's Filter.
'Notes: 1. We tack " AND " on the end of each condition so you can easily add more search boxes; _
we remove the trailing " AND " at the end.
' 2. The date range works like this: _
Both dates = only dates between (both inclusive. _
Start date only = all dates from this one onwards; _
End date only = all dates up to (and including this one).
Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria string to append to.
Const conJetDate = "\#mm\/dd\/yyyy\#" 'The format expected for dates in a JET query string.

'***********************************************************************
'Look at each search box, and build up the criteria string from the non-blank ones.
'***********************************************************************

'Text field example. Use quotes around the value in the string.
'If Not IsNull(Me.txtFilterCity) Then
'strWhere = strWhere & "([City] = """ & Me.txtFilterCity & """) AND "
'End If

'Another text field example. Use Like to find anywhere in the field.
'If Not IsNull(Me.txtFilterMainName) Then
'strWhere = strWhere & "([MainName] Like ""*" & Me.txtFilterMainName & "*"") AND "
'End If

'Number field example. Do not add the extra quotes.
If Not IsNull(Me.cboItem) Then
strWhere = strWhere & "([Transaction Item] = " & Me.cboItem & ") AND "
'Label234.Visible = False
End If

If Not IsNull(Me.cboSupplier) Then
strWhere = strWhere & "([Transaction Type] = " & Me.cboSupplier & ") AND "
'Label278.Visible = False
End If



'Yes/No field and combo example. If combo is blank or contains "ALL", we do nothing.
'If Me.cboFilterIsCorporate = -1 Then
'strWhere = strWhere & "([IsCorporate] = True) AND "
'ElseIf Me.cboFilterIsCorporate = 0 Then
'strWhere = strWhere & "([IsCorporate] = False) AND "
' End If

'Date field example. Use the format string to add the # delimiters and get the right international format.
If Not IsNull(Me.txtStartDate) Then
strWhere = strWhere & "([Created Date] >= " & Format(Me.txtStartDate, conJetDate) & ") AND "
'Label277.Visible = False
End If

'Another date field example. Use "less than the next day" since this field has times as well as dates.
If Not IsNull(Me.txtEndDate) Then 'Less than the next day.
strWhere = strWhere & "([Created Date] < " & Format(Me.txtEndDate + 1, conJetDate) & ") AND "
'Label260.Visible = False
End If

'***********************************************************************
'Chop off the trailing " AND ", and use the string as the form's Filter.
'***********************************************************************
'See if the string has more than 5 characters (a trailng " AND ") to remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.

MsgBox "×ùñßò êñéôÞñéá", vbInformation, "Êáìßá åíÝñãåéá."


Else 'Yep: there is something there, so remove the " AND " at the end.
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to Immediate Window (Ctrl+G).
'Debug.Print strWhere



'Finally, apply the string as the form's Filter.
Me.Filter = strWhere
Me.FilterOn = True

End If
End Sub

Wher can i put yours
 

mikekal

Member
Local time
, 21:18
Joined
Jun 24, 2017
Messages
114
When im puting that code doing thar:

Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone

If TickBox Then
With rs
.MoveFirst
Do While Not .EOF
.Edit
!Select = True
.Update
.MoveNext
Loop
End With
Me.Recordset.Requery
Else

DoCmd.OpenQuery "qryDeSelectAll", acViewNormal, acEdit
Me.Recordset.Requery
End If
Set rs = Nothing
 

Gasman

Enthusiastic Amateur
Local time
Today, 05:18
Joined
Sep 21, 2011
Messages
14,533
Not even sure what you are asking now? :(
You have a constant for date format, and you have your filter.?

All I supplied was the ability to check all filtered records.
I did say that you would have to apply the same logic if you deselect the Select All checkbox, in which case set select to False.

Now you could use
Code:
Private Sub TickBox_AfterUpdate()
    Dim rs As DAO.Recordset
    Set rs = Me.RecordsetClone

    With rs
        .MoveFirst
        Do While Not .EOF
            .Edit
            !Select = Me.TickBox
            .Update
            .MoveNext
        Loop
    End With
    Me.Recordset.Requery
    Set rs = Nothing
End Sub
 

mikekal

Member
Local time
, 21:18
Joined
Jun 24, 2017
Messages
114
Can i put in that code the undo ,when im selecting from combo box the value "undo"

Private Sub cmdDelete_Click()
Dim db As DAO.Database
'Dim ER As Integer
Set db = CurrentDb()
If Not IsNull(Me.Combo344) Then
strWhere = strWhere & " AND [Delete]=" & Me.Combo344
db.Execute "qryDelete", dbFailOnError

Me.Recordset.Requery
End If


'If Not IsNull(Me.Combo344) Then

'strWhere = strWhere & " AND [Undo]=" & Me.Combo344
'CmdDelete.Enabled = True
'DoCmd.RunCommand acCmdUndo
'DoCmd.Close
'End If

Set db = Nothing

End Sub
 

mikekal

Member
Local time
, 21:18
Joined
Jun 24, 2017
Messages
114
Can i put in that code the undo ,when im selecting from combo box the value "undo"

Private Sub cmdDelete_Click()
Dim db As DAO.Database
'Dim ER As Integer
Set db = CurrentDb()
If Not IsNull(Me.Combo344) Then
strWhere = strWhere & " AND [Delete]=" & Me.Combo344
db.Execute "qryDelete", dbFailOnError

Me.Recordset.Requery
End If


'If Not IsNull(Me.Combo344) Then

'strWhere = strWhere & " AND [Undo]=" & Me.Combo344
'CmdDelete.Enabled = True
'DoCmd.RunCommand acCmdUndo
'DoCmd.Close
'End If

Set db = Nothing

End Sub
 

Attachments

  • TickBoxTemp (1).accdb
    856 KB · Views: 51

mikekal

Member
Local time
, 21:18
Joined
Jun 24, 2017
Messages
114
I,d like to do delete or undo with combobox selection.Thank you
 

Gasman

Enthusiastic Amateur
Local time
Today, 05:18
Joined
Sep 21, 2011
Messages
14,533
Little impatient aren't we? :(

All my code did is mark records or clear records in a filtered form.
You can use whatever you like to run the query to delete.
Start giving the controls some meaningful names. 6 months down the line, combo344 is not going to mean anything to anyone.
In hospital car park on phone, so cannot view db.
 

mikekal

Member
Local time
, 21:18
Joined
Jun 24, 2017
Messages
114
I would like when i use combo box to delete or undo a record.Im sorry for bad english
 

Gasman

Enthusiastic Amateur
Local time
Today, 05:18
Joined
Sep 21, 2011
Messages
14,533
When you delete in access, it is deleted, no undo. Access is not Foxpro. :)
 

mikekal

Member
Local time
, 21:18
Joined
Jun 24, 2017
Messages
114
When you delete in access, it is deleted, no undo. Access is not Foxpro. :)
Im saing that i im choose delete from combo im delete the record.If im choose undo from combo im undoing what im writing in that time
 

Gasman

Enthusiastic Amateur
Local time
Today, 05:18
Joined
Sep 21, 2011
Messages
14,533
Please put the steps you expect.
Me.
1. Mark records for delete
2. Delete records
3. OR Before I do 2, I unselect records marked as deleted, so 2 will not happen
 

Users who are viewing this thread

Top Bottom