B
Bill Benson
I have a bound listbox control on a form whose MouseUp event is firing for
some reason between when I double-click the Form to load it, and when
control passes to the user. I am *not aware* of anything going on in the
code to cause this, and there is no call to the MouseUp event nor any class
modules which hook that control, which could be causing it. It has been a
long time since I coded in Access and I cannot say I have used this control
event much anyway -- but it would seem to me to not be an intuitive
behavior. Some stuff happens in that event which I can't really control, I
would like to stop if from firing on the loading of a form. I have checked
the call stack and no other events or procedures appear to precede the
MouseUp event, so it is behaving exactly like I clicked the mouse on the
control, when for certain I have not.
Here is the code in the Load event, maybe one of these statements is causing
the MouseUp event to fire? Still, if so, I would expect to see
PopulateListofFields in the call stack.
Private Sub Form_Load()
PopulateListofFields
End Sub
Function PopulateListofFields()
Dim Conn As ADODB.Connection
Dim rsCheckTable As ADODB.Recordset
Dim i As Long
Dim Prp As DAO.Property
Dim Fld As DAO.Field
Dim d As DAO.Database
Dim SQL As String
Dim T As DAO.TableDef
Set Conn = CurrentProject.Connection
Set rsCheckTable = CreateObject("ADODB.Recordset")
On Error Resume Next
lstFields.RowSource = ""
lstFields.Requery
lstFieldChoices.RowSource = ""
lstFieldChoices.Requery
'DoCmd.DeleteObject acTable, "Tbl_GIB_Fields_Used"
'Test that the items in "Tbl_GIB_Fields_Used" are "in Tbl_GIB_Fields", and
make the items in "Tbl_GIB_Fields" Selected which are in
"Tbl_GIB_Fields_Used".
DoCmd.SetWarnings False
Conn.Execute "DELETE * from Tbl_GIB_Fields_Used WHERE Tbl_GIB_Fields_Used.ID
not in (Select Tbl_GIB_Fields_Used.ID from Tbl_GIB_Fields_Used LEFT join
Tbl_GIB_Fields on (Tbl_GIB_Fields_Used.ID = Tbl_GIB_Fields.ID))"
DoCmd.SetWarnings True
DoCmd.DeleteObject acTable, "Tbl_GIB_Fields"
CurrentDb.TableDefs.Refresh
Conn.Execute "CREATE TABLE Tbl_GIB_Fields( ID INTEGER NOT NULL, DataField
VARCHAR(255) NOT NULL, USE YesNo)"
Set d = CurrentDb
Set T = d.TableDefs("Tbl_GIB_Fields")
Set Fld = T.Fields("USE")
Set Prp = Fld.CreateProperty("DisplayControl", dbInteger, acCheckBox)
Fld.Properties.Append Prp
Set Prp = Fld.CreateProperty("Format", dbText, "Yes/No")
Fld.Properties.Append Prp
Fld.Properties.Refresh
On Error GoTo 0
Set rsCheckTable = Conn.OpenSchema(adSchemaColumns, Array(Empty, Empty,
"Tbl_GIB_All", Empty))
DoCmd.SetWarnings False
While Not rsCheckTable.EOF
i = i + 1
DoCmd.RunSQL ("Insert into Tbl_GIB_Fields (ID,DataField,USE) Values (" & i
& ",'" & rsCheckTable.Fields("COLUMN_NAME").Value & "',FALSE)")
rsCheckTable.MoveNext
Wend
SQL = "Update Tbl_GIB_Fields Set USE = TRUE where Tbl_GIB_Fields.ID in
(Select Tbl_GIB_Fields_Used.ID from Tbl_GIB_Fields_Used)"
DoCmd.SetWarnings False
DoCmd.RunSQL (SQL)
DoCmd.SetWarnings True
lstFields.RowSourceType = "Table/Query"
lstFieldChoices.RowSourceType = "Table/Query"
lstFields.ColumnCount = 2
lstFields.BoundColumn = 1
lstFields.ColumnHeads = True
lstFields.ColumnWidths = "0" & """" & ";2.5" & """"
lstFields.RowSource = "Select ID,DataField from Tbl_GIB_Fields Where Use =
False"
lstFields.Requery
lstFieldChoices.ColumnCount = 2
lstFieldChoices.BoundColumn = 1
lstFieldChoices.ColumnHeads = True
lstFieldChoices.ColumnWidths = "0" & """" & ";2.5" & """"
lstFieldChoices.RowSource = "Select ID,DataField from Tbl_GIB_Fields_Used"
lstFieldChoices.Requery
DoCmd.SetWarnings True
End Function
some reason between when I double-click the Form to load it, and when
control passes to the user. I am *not aware* of anything going on in the
code to cause this, and there is no call to the MouseUp event nor any class
modules which hook that control, which could be causing it. It has been a
long time since I coded in Access and I cannot say I have used this control
event much anyway -- but it would seem to me to not be an intuitive
behavior. Some stuff happens in that event which I can't really control, I
would like to stop if from firing on the loading of a form. I have checked
the call stack and no other events or procedures appear to precede the
MouseUp event, so it is behaving exactly like I clicked the mouse on the
control, when for certain I have not.
Here is the code in the Load event, maybe one of these statements is causing
the MouseUp event to fire? Still, if so, I would expect to see
PopulateListofFields in the call stack.
Private Sub Form_Load()
PopulateListofFields
End Sub
Function PopulateListofFields()
Dim Conn As ADODB.Connection
Dim rsCheckTable As ADODB.Recordset
Dim i As Long
Dim Prp As DAO.Property
Dim Fld As DAO.Field
Dim d As DAO.Database
Dim SQL As String
Dim T As DAO.TableDef
Set Conn = CurrentProject.Connection
Set rsCheckTable = CreateObject("ADODB.Recordset")
On Error Resume Next
lstFields.RowSource = ""
lstFields.Requery
lstFieldChoices.RowSource = ""
lstFieldChoices.Requery
'DoCmd.DeleteObject acTable, "Tbl_GIB_Fields_Used"
'Test that the items in "Tbl_GIB_Fields_Used" are "in Tbl_GIB_Fields", and
make the items in "Tbl_GIB_Fields" Selected which are in
"Tbl_GIB_Fields_Used".
DoCmd.SetWarnings False
Conn.Execute "DELETE * from Tbl_GIB_Fields_Used WHERE Tbl_GIB_Fields_Used.ID
not in (Select Tbl_GIB_Fields_Used.ID from Tbl_GIB_Fields_Used LEFT join
Tbl_GIB_Fields on (Tbl_GIB_Fields_Used.ID = Tbl_GIB_Fields.ID))"
DoCmd.SetWarnings True
DoCmd.DeleteObject acTable, "Tbl_GIB_Fields"
CurrentDb.TableDefs.Refresh
Conn.Execute "CREATE TABLE Tbl_GIB_Fields( ID INTEGER NOT NULL, DataField
VARCHAR(255) NOT NULL, USE YesNo)"
Set d = CurrentDb
Set T = d.TableDefs("Tbl_GIB_Fields")
Set Fld = T.Fields("USE")
Set Prp = Fld.CreateProperty("DisplayControl", dbInteger, acCheckBox)
Fld.Properties.Append Prp
Set Prp = Fld.CreateProperty("Format", dbText, "Yes/No")
Fld.Properties.Append Prp
Fld.Properties.Refresh
On Error GoTo 0
Set rsCheckTable = Conn.OpenSchema(adSchemaColumns, Array(Empty, Empty,
"Tbl_GIB_All", Empty))
DoCmd.SetWarnings False
While Not rsCheckTable.EOF
i = i + 1
DoCmd.RunSQL ("Insert into Tbl_GIB_Fields (ID,DataField,USE) Values (" & i
& ",'" & rsCheckTable.Fields("COLUMN_NAME").Value & "',FALSE)")
rsCheckTable.MoveNext
Wend
SQL = "Update Tbl_GIB_Fields Set USE = TRUE where Tbl_GIB_Fields.ID in
(Select Tbl_GIB_Fields_Used.ID from Tbl_GIB_Fields_Used)"
DoCmd.SetWarnings False
DoCmd.RunSQL (SQL)
DoCmd.SetWarnings True
lstFields.RowSourceType = "Table/Query"
lstFieldChoices.RowSourceType = "Table/Query"
lstFields.ColumnCount = 2
lstFields.BoundColumn = 1
lstFields.ColumnHeads = True
lstFields.ColumnWidths = "0" & """" & ";2.5" & """"
lstFields.RowSource = "Select ID,DataField from Tbl_GIB_Fields Where Use =
False"
lstFields.Requery
lstFieldChoices.ColumnCount = 2
lstFieldChoices.BoundColumn = 1
lstFieldChoices.ColumnHeads = True
lstFieldChoices.ColumnWidths = "0" & """" & ";2.5" & """"
lstFieldChoices.RowSource = "Select ID,DataField from Tbl_GIB_Fields_Used"
lstFieldChoices.Requery
DoCmd.SetWarnings True
End Function