Irfan Salim
Registered User.
- Local time
- Today, 20:29
- Joined
- Oct 3, 2002
- Messages
- 16
I made a table Employee. Then I made an Employeeform whose recordsource was table Employee.
Then I made a table ItemDisplay whose fields are ItemID, ItemCaption, ItemName, ItemParent, ItemShow.
I entered all fields of table Employee in table ItemDisplay with ItemID an autonumber, ItemCaption as field caption, ItemName, the name of field in Employee table, ItemParent Employee and ItemShow Yes for some of the fields.
Then I made a query named DataSheetView with those fields from the Employee Table whose ItemShow is Yes in the ItemDisplay Table.
On the EmployeeForm, I made a commandbutton that opens a form SelectFieldsDialog. RecordSource of this form is ItemDisplay. This form gives user the option to select fields that should be displayed in Data Sheet View.
After the user checks the fields, he can press OK button.
Code in cmdOK_Click is as follows:
Private Sub cmdOK_Click()
Dim db As Database
Dim rs As Recordset
Dim qdf As QueryDef
Dim strSQL As String
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
strSQL = strSQL & rs!ItemName & ", "
End If
rs.MoveNext
Loop
DoCmd.Close
strSQL = Left(strSQL, Len(strSQL) - 2) & " From Employee"
qdf.SQL = strSQL
DoCmd.OpenQuery qdf.Name
End Sub
When I run this form and after selecting desired fields, when I press OK, I get the following error:
13: Type Mismatch
This error occured at the following line:
Set rs = Me.RecordsetClone
Then I made a table ItemDisplay whose fields are ItemID, ItemCaption, ItemName, ItemParent, ItemShow.
I entered all fields of table Employee in table ItemDisplay with ItemID an autonumber, ItemCaption as field caption, ItemName, the name of field in Employee table, ItemParent Employee and ItemShow Yes for some of the fields.
Then I made a query named DataSheetView with those fields from the Employee Table whose ItemShow is Yes in the ItemDisplay Table.
On the EmployeeForm, I made a commandbutton that opens a form SelectFieldsDialog. RecordSource of this form is ItemDisplay. This form gives user the option to select fields that should be displayed in Data Sheet View.
After the user checks the fields, he can press OK button.
Code in cmdOK_Click is as follows:
Private Sub cmdOK_Click()
Dim db As Database
Dim rs As Recordset
Dim qdf As QueryDef
Dim strSQL As String
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
strSQL = strSQL & rs!ItemName & ", "
End If
rs.MoveNext
Loop
DoCmd.Close
strSQL = Left(strSQL, Len(strSQL) - 2) & " From Employee"
qdf.SQL = strSQL
DoCmd.OpenQuery qdf.Name
End Sub
When I run this form and after selecting desired fields, when I press OK, I get the following error:
13: Type Mismatch
This error occured at the following line:
Set rs = Me.RecordsetClone