N
Nhan
Hi,
I have a form master "M" linked with a datasheet subform "SF" on it.
The subform is a normal form, but is shown in datasheet modus.
The subform cannot remember its columns sizes, which the users set. It show
columns only in original size. Therefore my program must save the
columnwidth of each column in a table (at form_close event) and restore it
at Form_load event of the subform ("RestoreFormColumnsInforms").
These functions work gut, but
- when I quit access, a system error occurs: MS Access for windows ... a
problem and must be shut down (I translate the message from German).
- when I open also from the main form "M" (by klicking a button) another
similar form (with subform in datasheet and columns solution), then I cannot
quit access anymore: the database is closed, but access window not, I must
always use Ctrl+Alt+Del to close access window.
- **** But when I open the form "SF" directly, that means, now it isn't a
subform, then there is "no problem", Access is shut down normally.
I am sure, that these functions cause this problem. when I delete the line,
which calls the function "RestoreFormColumnsInforms", then there is "no
problem". But this function runs correct, that means, it runs completely...
Why?
Thanks
Nhan
Following is the function
Public Function RestoreFormColumnsInforms(p_oForm As Form) As Boolean
Dim ctrl As Control
Dim rs As DAO.Recordset
Dim sSQL As String
Dim bIsSubForm As Boolean
Dim bIsHidden As Boolean
Dim db As DAO.Database
Dim oControls As Access.Controls
Set db = CurrentDb
sSQL = "SELECT * FROM _MyFormControls where FormName = " & p_oForm.Name
Set rs = db.OpenRecordset(sSQL)
Set oControls = p_oForm.Controls
On Error Resume Next
While Not rs.EOF
Set ctrl = oControls(rs!ControlName)
If Err.Number <> 0 Then GoTo nextControl
bIsHidden = rs!Hidden
If bIsHidden = True Then
ctrl.ColumnHidden = true
End If
ctrl.ColumnOrder = rs!Order
If Not bIsHidden Then ctrl.ColumnWidth = rs!Width
nextControl:
Err.Clear
rs.MoveNext
Wend
On Error Resume Next
rs.Close
RestoreFormColumnsInforms = true
end function
I have a form master "M" linked with a datasheet subform "SF" on it.
The subform is a normal form, but is shown in datasheet modus.
The subform cannot remember its columns sizes, which the users set. It show
columns only in original size. Therefore my program must save the
columnwidth of each column in a table (at form_close event) and restore it
at Form_load event of the subform ("RestoreFormColumnsInforms").
These functions work gut, but
- when I quit access, a system error occurs: MS Access for windows ... a
problem and must be shut down (I translate the message from German).
- when I open also from the main form "M" (by klicking a button) another
similar form (with subform in datasheet and columns solution), then I cannot
quit access anymore: the database is closed, but access window not, I must
always use Ctrl+Alt+Del to close access window.
- **** But when I open the form "SF" directly, that means, now it isn't a
subform, then there is "no problem", Access is shut down normally.
I am sure, that these functions cause this problem. when I delete the line,
which calls the function "RestoreFormColumnsInforms", then there is "no
problem". But this function runs correct, that means, it runs completely...
Why?
Thanks
Nhan
Following is the function
Public Function RestoreFormColumnsInforms(p_oForm As Form) As Boolean
Dim ctrl As Control
Dim rs As DAO.Recordset
Dim sSQL As String
Dim bIsSubForm As Boolean
Dim bIsHidden As Boolean
Dim db As DAO.Database
Dim oControls As Access.Controls
Set db = CurrentDb
sSQL = "SELECT * FROM _MyFormControls where FormName = " & p_oForm.Name
Set rs = db.OpenRecordset(sSQL)
Set oControls = p_oForm.Controls
On Error Resume Next
While Not rs.EOF
Set ctrl = oControls(rs!ControlName)
If Err.Number <> 0 Then GoTo nextControl
bIsHidden = rs!Hidden
If bIsHidden = True Then
ctrl.ColumnHidden = true
End If
ctrl.ColumnOrder = rs!Order
If Not bIsHidden Then ctrl.ColumnWidth = rs!Width
nextControl:
Err.Clear
rs.MoveNext
Wend
On Error Resume Next
rs.Close
RestoreFormColumnsInforms = true
end function