[AccessD] Dynamically calling combobox_afterupdate from form_open event
Jim Dettman
jimdettman at verizon.net
Mon Mar 6 13:52:45 CST 2023
Ryan,
1. You are using the OnOpen event, and controls might not be instantiated
as yet.
Put a:
Me.Repaint
At the top of the procedure to force that (assuming you are using OnOpen
because it is cancelable - If not, move the code to the OnLoad).
2. Would suggest making it a little more generic:
Sub SetControlsToData(frm As Form, strData As String)
' Set controls on frm to values contained in strData.
' Delimiter is a ":". Format of strData is control name: value.
Dim intPairNumber As Integer
Dim varControlName As Variant
Dim varData As Variant
10 intPairNumber = 1
20 Do
30 varControlName = dhExtractString(strData, intPairNumber, ":")
40 If varControlName = "" Then Exit Do
50 varData = dhExtractString(strData, intPairNumber + 1, ":")
60 frm(varControlName) = varData
70 intPairNumber = intPairNumber + 2
80 Loop
End Sub
And call that from the OnOpen(). In fact, I take that even further. I've
use OpenArgs like this:
"ADD;SETCTRLTODATA=txtName:" & NewData & ";EXITTOFORM=frmCustomers"
Which is the mode the form should open in (Add, Edit, or Inquiry), setting
controls to data, and what form to exit to when it's closed. I had a
framework where this was part of a standard OpenForm call. I also used
the same type of setup for Control Tags, to control things like placement,
security, etc.
The underlying routines are the get/put Tags from the Access Developers
Handbook.
HTH,
Jim.
-----Original Message-----
From: AccessD On Behalf Of Ryan W
Sent: Monday, March 6, 2023 2:03 PM
To: Access Developers discussion and problem solving
<accessd at databaseadvisors.com>
Subject: [AccessD] Dynamically calling combobox_afterupdate from form_open
event
I have a form that takes openargs, the openargs are such as:
cbxJobID|12345
The key/pair set can be repeated.. the key is the control name, the other
is the data to input into the control name
my form open event is as such:
Private Sub Form_Open(Cancel As Integer)
Dim l As Long: l = 0
Dim strArgs() As String
If IsNull(Me.OpenArgs) Then Exit Sub
strArgs = Split(Me.OpenArgs, "|")
For l = 0 To UBound(strArgs) Step 2
Me(strArgs(l)) = strArgs(l + 1)
Call Eval(strArgs(l) & "_AfterUpdate")
Next l
End Sub
The problem I'm having is the "Call Eval()" part. I get an error:
"Run-Time error '2482':
Cannot find name 'cbxJobID_AfterUpdate' you entered in the expression.
However that exists. I've tried making it a public sub, private sub,
public or private function.
None of it seems to work. Maybe it can't be a form level function/sub, has
to be module level?
The microsoft documentation under examples shows the method I'm using is
supported:
https://learn.microsoft.com/en-us/office/vba/api/access.application.eval
The following example assumes that you have a series of 50 functions
defined as A1, A2, and so on. This example uses the *Eval* function to call
each function in the series.
Sub CallSeries()
Dim intI As Integer
For intI = 1 To 50
Eval("A" & intI & "()")
Next intI
End Sub
So, something is missing here... can anyone clue me in?
--
AccessD mailing list
AccessD at databaseadvisors.com
https://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
More information about the AccessD
mailing list