Subform tick box

aman909

Registered User.
Local time
Today, 13:00
Joined
Jun 20, 2007
Messages
28
I have a form which contains a subform. This subform is in datasheet format.

The subform contains a yes/no field. This is a tick box.
What i would like to do is just to be able to delete the records which are ticked.

For example if i have 10records in my subform but only 4 are ticked, then i would only like to delete these 4 records.

How would this be possible?
 
.
Create a query that deletes the records you have selected. Add the SQL version of that query to a function something similar to the one below, and call that code with a command button.

Code:
Function fSetDefault(strDfault As String, strCurVal As String)
'From: http://support.microsoft.com/default.aspx?scid=kb;EN-US;202117

'This function sets the default value (a string) in the table "tblDefault" it requires three
'pieces of information to operate, the current windows username which it finds With the code below.
'the name of the default which is passed through the variable "strDfault" and the current
'value of that default,which is passed through the variable "strCurVal" the value of
'the default is saved in the table "tblDfault"
'Occasionally the table does not have a default entry listed. this code does not react,
'it does nothing, it does not throw an error or anything!
'Hence the need for the function "fInitaliseDfault" below.
'This function initializes the table, adding an entry if none exists, and throwing an error
'if creating a duplicate is attempted. This error is trapped and passed back to
'the function "fInitaliseDfault" as a boolean.

   On Error GoTo Err_ErrorHandler
   
   If fInitaliseDfault(strDfault, strCurVal) Then Exit Function 'Exit if creating a duplicate is attempted
   
Dim strUserName As String
'
'strUserName = fGetWinUserName() 'Your windows login name
strUserName = fUserGet
strUserName = "'" & strUserName & "'"

Dim strDfaultText As String
strDfaultText = "'" & strDfault & "'"

Dim strCurText As String
strCurText = "'" & strCurVal & "'"
   
    Dim adoCon As ADODB.Connection
    Dim adoCmd As ADODB.Command

   Set adoCon = CurrentProject.Connection
   Set adoCmd = New ADODB.Command

Dim strSQL As String
Dim strSQL1 As String
Dim strSQL2 As String
Dim strSQL3 As String
Dim strSQL4 As String
Dim strSQL5 As String

strSQL1 = "UPDATE tblDefaults SET tblDefaults.DfaultVal = "
strSQL2 = "WHERE (((tblDefaults.DfaultUser)="
strSQL3 = ") AND ((tblDefaults.DfaultFor)="
strSQL4 = "));"

strSQL = strSQL1 & strCurText & strSQL2 & strUserName & strSQL3 & strDfaultText & strSQL4

   With adoCmd
        .ActiveConnection = adoCon
        .CommandType = adCmdText
        .CommandText = strSQL
        .Execute
   End With

Exit_ErrorHandler:
        adoCon.Close
    Set adoCon = Nothing
    Set adoCmd = Nothing
    
    Exit Function 'Sub Property

Err_ErrorHandler:
        Select Case Err.Number
            Case 1 'Not sure if there is an error code (1) I have never seen it yet
                MsgBox "produced by error code (1) please check your code ! Error Number >>>  " _
                & Err.Number & "  Error Desc >>  " & Err.Description, , conAppName
            Case Else
                MsgBox "Error From --- fGetDefault --- Error Number >>>  " & Err.Number _
                & "  <<< Error Description >>  " & Err.Description, , conAppName
        End Select
    Resume Exit_ErrorHandler
End Function      'fSetDefault()
 

Users who are viewing this thread

Back
Top Bottom