Access analysis: two functions are used to delete records that meet certain conditions for a field in a table.

Source: Internet
Author: User
I. Call method: SubAcchelp_Test () if the condition is long-integer CallAccHelp_DeleteFldNumRow (Table Name, field name, condition) if the condition is text-type CallAccHelp_DeleteFldStrRow (Table Name, field name, condition) endSub 2. two functions: PublicFunction

I. Call method: Sub Acchelp_Test () 'If the condition is a long integer Call AccHelp_DeleteFldNumRow ("table name", "field name", condition) 'If the condition is text type 'call AccHelp_DeleteFldStrRow ("table name", "field name", condition) End Sub 2. two functions: Public Function

I. Call method:

Sub Acchelp_Test ()

'If yesConditionIs a long integer

Call AccHelp_DeleteFldNumRow ("table name ","FieldName ",Condition)

'If yesConditionIs text type

'Call AccHelp_DeleteFldStrRow ("table name ","FieldName ",Condition)

End Sub

Ii. TwoFunction:

Public Function AccHelp_DeleteFldStrRow (tblName As String, conditionFldName As String, strCondition As String)

'Function: according toFieldConditionDeleteA tableFieldYesCondition(Must be text) The whole lineRecordTo reference DAO3.6.

'Generally, it is used based on the text order number (or contract number ).DeleteOne in the tableRecord, OrDeleteYesConditionMultipleRecord

'Modification history: 2006/1/3

'Note:

'Tblname indicates the table name.

'Conditionfldname refers to the applicationConditionFieldName

'Strcondition refersCondition

'Author: Zhu Di (Microsoft's most valuable expert)

'Note: You can apply this in your own software for free.FunctionIn order to respect the work of the author, please keep these instructions. At the same time, you may not use it for profitable commercial purposes. You are welcome to submit your comments for modification andFunctionCommunicate with author

'Mail: admin@accessoft.com

On Error GoTo Err_AccHelp_DeleteFldStrRow:

Dim strSQL As String

Dim rst As DAO. Recordset

Set rst = CurrentDb. OpenRecordset (tblName, dbOpenDynaset)

Rst. MoveFirst

Do Until rst. EOF

If rst (conditionFldName) = strCondition Then

Rst. Delete

End If

Rst. MoveNext

Loop

Rst. Close

Set rst = Nothing

Exit_AccHelp_DeleteFldStrRow:

Exit Function

Err_AccHelp_DeleteFldStrRow:

Rst. Close

Set rst = Nothing

Resume Exit_AccHelp_DeleteFldStrRow

End Function

Public Function AccHelp_DeleteFldNumRow (tblName As String, conditionFldName As String, NumCondition As Long)

'Function: according toFieldConditionDeleteA tableFieldYesCondition(Must be a long integer number ).RecordTo reference DAO3.6.

'Is generally used according to the serial numberDeleteOne in the tableRecord, OrDeleteYesConditionMultipleRecord

'Modification history: 2006/1/3

'Note:

'Tblname indicates the table name.

'Conditionfldname refers to the applicationConditionFieldName

'Numcondition refersCondition

'Author: Zhu Di (Microsoft's most valuable expert)

'Note: You can apply this in your own software for free.FunctionIn order to respect the work of the author, please keep these instructions. At the same time, you may not use it for profitable commercial purposes. You are welcome to submit your comments for modification andFunctionCommunicate with author

'Mail: admin@accessoft.com

On Error GoTo Err_AccHelp_DeleteFldNumRow:

Dim strSQL As String

Dim rst As DAO. Recordset

Set rst = CurrentDb. OpenRecordset (tblName, dbOpenDynaset)

Rst. MoveFirst

Do Until rst. EOF

If rst (conditionFldName) = NumCondition Then

Rst. Delete

End If

Rst. MoveNext

Loop

Rst. Close

Set rst = Nothing

Exit_AccHelp_DeleteFldNumRow:

Exit Function

Err_AccHelp_DeleteFldNumRow:

Rst. Close

Set rst = Nothing

Resume Exit_AccHelp_DeleteFldNumRow

End Function

Reference self-Webmaster network http://www.software8.co/shujuku/access/2395.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.