khicon73
MIS
- Jan 10, 2008
- 36
I have a continues form to show all item to be able to check and uncheck to view the query. it's working fine with the code below.
I have 2 questions on this form:
First, how do I sort the record based on user selected?
Second, I need to add a check box and named "chkAll". I would like if this box checked, then the "ItemShow" in the code below would like to turn to "True"...Please help...thanks.
Private Sub cmdOK_Click()
' Display only selected fields in Client
' form in datasheet view
Dim DB As Database
Dim RS As Recordset
Dim qdf As QueryDef
Dim strSQL As String
On Error GoTo HandleErr
' save current record
DoCmd.RunCommand acCmdSaveRecord
Set DB = CurrentDb
Set qdf = DB.QueryDefs("DatasheetView")
strSQL = "Select "
Set RS = Me.RecordsetClone
RS.MoveFirst
Do Until RS.EOF
If RS!ItemShow = True Then
' Build SQL string
strSQL = strSQL & RS!ItemName & ", "
End If
RS.MoveNext
Loop
DoCmd.Close
strSQL = Left(strSQL, Len(strSQL) - 2) & " From tblDisease"
qdf.SQL = strSQL
DoCmd.OpenQuery qdf.Name
ExitHere:
Exit Sub
HandleErr:
Select Case Err
Case Else
MsgBox Err & ": " & Err.Description, vbCritical, _
"Error in Form_[_frm_SelectFieldsDialog].cmdOK_Click "
End Select
Resume ExitHere
Resume
End Sub
I have 2 questions on this form:
First, how do I sort the record based on user selected?
Second, I need to add a check box and named "chkAll". I would like if this box checked, then the "ItemShow" in the code below would like to turn to "True"...Please help...thanks.
Private Sub cmdOK_Click()
' Display only selected fields in Client
' form in datasheet view
Dim DB As Database
Dim RS As Recordset
Dim qdf As QueryDef
Dim strSQL As String
On Error GoTo HandleErr
' save current record
DoCmd.RunCommand acCmdSaveRecord
Set DB = CurrentDb
Set qdf = DB.QueryDefs("DatasheetView")
strSQL = "Select "
Set RS = Me.RecordsetClone
RS.MoveFirst
Do Until RS.EOF
If RS!ItemShow = True Then
' Build SQL string
strSQL = strSQL & RS!ItemName & ", "
End If
RS.MoveNext
Loop
DoCmd.Close
strSQL = Left(strSQL, Len(strSQL) - 2) & " From tblDisease"
qdf.SQL = strSQL
DoCmd.OpenQuery qdf.Name
ExitHere:
Exit Sub
HandleErr:
Select Case Err
Case Else
MsgBox Err & ": " & Err.Description, vbCritical, _
"Error in Form_[_frm_SelectFieldsDialog].cmdOK_Click "
End Select
Resume ExitHere
Resume
End Sub