N
Niklas Östergren
Hi!
Is there a limit of how many number of call´s for a code module I can have
in a form module?
I have a QBF in which I have 15 pcs of checkboxes. I loop through all of
them to see if they are checked or not when I close the QBF. If so I´ll set
a value (using DAO method) in a localy stored table.
When the form is opened again I check the table (using Seek method) to see
if the checkbox was checked or not. And if so I´ll set it to checked again.
This is to make it a little bit easyer for the user to see what was selected
last time the form was opend and what data do I have in tha result table
right now before any new selection.
I have now run into a new problem. If I run the code in runtime it will not
work. The value will not change in the table. But if I stope the code during
running. I don´t know the correct english word for this but what happens
when I stop the code is that when I close the form (after any selection) the
the code will stop running and the code window will show up with the row of
code highlighted with yellow where I placed the stop.
If I run the code with a stop in it everything work´s just fine.
Any help would be highly apreciated!
TIA!
// Niklas
Here´s the code I use:
********************************************************
Private Sub Form_Unload(Cancel As Integer)
Dim intNewValue As Integer
'======================================================
' DOB (This is only one of several checkboxes)
'======================================================
If chkDoB Then
intNewValue = Me![chkDoB]
strNewDescription = "Födelsedatum har valts!"
Call SetIntegerValueIntblStorage("tblStorage", "ColumnDoB", intNewValue,
strNewDescription)
Else
strNewDescription = "Födelsedatum har INTE valts!"
Call SetNullIntegerValueIntblStorage("tblStorage", "ColumnDoB",
strNewDescription)
End If
End Sub
**************************************************************
Since I call function **SetIntegerValueIntblStorage** several times I have
made this function public.
**************************************************************
Public Function SetIntegerValueIntblStorage(strTableName As String,
strVariableName As String, _
intValueToSetInTable As Integer, strDescriptionMsg
As String)
'strTableName Holds table name to store value in.
'strVariableName Holds variablename to seek for in table.
'intValueToSetInTable Holds value to set in table.
'strDescriptionMsg Holds description to put in table.
Dim db As Database, rst As Recordset
Set db = Currentdb
Set rst = db.OpenRecordset(strTableName)
rst.Index = "PrimaryKey"
rst.Seek "=", strVariableName
' If not found, create the entry.
If rst.NoMatch Then
rst.AddNew
rst![Variable] = strVariableName
rst![Value] = intValueToSetInTable
rst![Description] = strDescriptionMsg
rst.Update ' Update the recordset.
Else
rst.Edit
rst![Value] = intValueToSetInTable
rst![Description] = strDescriptionMsg
rst.Update ' Update the recordset.
End If
rst.Close ' Close the recordset.
End Function
Is there a limit of how many number of call´s for a code module I can have
in a form module?
I have a QBF in which I have 15 pcs of checkboxes. I loop through all of
them to see if they are checked or not when I close the QBF. If so I´ll set
a value (using DAO method) in a localy stored table.
When the form is opened again I check the table (using Seek method) to see
if the checkbox was checked or not. And if so I´ll set it to checked again.
This is to make it a little bit easyer for the user to see what was selected
last time the form was opend and what data do I have in tha result table
right now before any new selection.
I have now run into a new problem. If I run the code in runtime it will not
work. The value will not change in the table. But if I stope the code during
running. I don´t know the correct english word for this but what happens
when I stop the code is that when I close the form (after any selection) the
the code will stop running and the code window will show up with the row of
code highlighted with yellow where I placed the stop.
If I run the code with a stop in it everything work´s just fine.
Any help would be highly apreciated!
TIA!
// Niklas
Here´s the code I use:
********************************************************
Private Sub Form_Unload(Cancel As Integer)
Dim intNewValue As Integer
'======================================================
' DOB (This is only one of several checkboxes)
'======================================================
If chkDoB Then
intNewValue = Me![chkDoB]
strNewDescription = "Födelsedatum har valts!"
Call SetIntegerValueIntblStorage("tblStorage", "ColumnDoB", intNewValue,
strNewDescription)
Else
strNewDescription = "Födelsedatum har INTE valts!"
Call SetNullIntegerValueIntblStorage("tblStorage", "ColumnDoB",
strNewDescription)
End If
End Sub
**************************************************************
Since I call function **SetIntegerValueIntblStorage** several times I have
made this function public.
**************************************************************
Public Function SetIntegerValueIntblStorage(strTableName As String,
strVariableName As String, _
intValueToSetInTable As Integer, strDescriptionMsg
As String)
'strTableName Holds table name to store value in.
'strVariableName Holds variablename to seek for in table.
'intValueToSetInTable Holds value to set in table.
'strDescriptionMsg Holds description to put in table.
Dim db As Database, rst As Recordset
Set db = Currentdb
Set rst = db.OpenRecordset(strTableName)
rst.Index = "PrimaryKey"
rst.Seek "=", strVariableName
' If not found, create the entry.
If rst.NoMatch Then
rst.AddNew
rst![Variable] = strVariableName
rst![Value] = intValueToSetInTable
rst![Description] = strDescriptionMsg
rst.Update ' Update the recordset.
Else
rst.Edit
rst![Value] = intValueToSetInTable
rst![Description] = strDescriptionMsg
rst.Update ' Update the recordset.
End If
rst.Close ' Close the recordset.
End Function