Eval function

A

Amy Blankenship

I have a popup form I'd like to potentially call from more than one place.
So I'm trying to pass it the path to the calling subform and have it set a
control value on the calling form when it is closed. So what I have is
this:

in the calling form:

Private Sub LaunchQuestion_Click()
Dim WhereClause As String
If Me.QuestionID Is Not Null Then
WhereClause = "QuestionID = " + Me.QuestionID
Else
WhereClause = "IS NULL"
End If

DoCmd.OpenForm "Question Subform", , , WhereClause, , acDialog,
Me.Parent.Parent.Parent.Name + "+" + Me.Parent.Parent.Name + "+" +
Me.Parent.Name + "+" + Me.Name
Debug.Print Me.Parent.Parent.Name + "+" + Me.Parent.Name + "+" + Me.Name
End Sub


Then, in the popup:

Private Sub Form_Unload(Cancel As Integer)
Dim arrArg As Variant, strForm As Variant, strEval As String
arrArg = Split(Me.OpenArgs, "+")
strEval = "Forms"
For Each strForm In arrArg
strEval = strEval & "![" & strForm & "]"
Next strForm
strEval = strEval & "=" & Me.QuestionID
Eval (strEval)
End Sub

I get an error message from Access "A property of the Automation object
requires or returns a value that isn't supported by visual basic."

Obviously, there's got to be a way to reference a form when the full path to
it can be a variable length, but I'm durned if I know what it is. I tried
just passing a full on reference to the control in question, but access
didn't like the data type.

Thanks;

Amy
 
M

Marshall Barton

Amy said:
I have a popup form I'd like to potentially call from more than one place.
So I'm trying to pass it the path to the calling subform and have it set a
control value on the calling form when it is closed. So what I have is
this:

in the calling form:

Private Sub LaunchQuestion_Click()
Dim WhereClause As String
If Me.QuestionID Is Not Null Then
WhereClause = "QuestionID = " + Me.QuestionID
Else
WhereClause = "IS NULL"
End If

DoCmd.OpenForm "Question Subform", , , WhereClause, , acDialog,
Me.Parent.Parent.Parent.Name + "+" + Me.Parent.Parent.Name + "+" +
Me.Parent.Name + "+" + Me.Name
Debug.Print Me.Parent.Parent.Name + "+" + Me.Parent.Name + "+" + Me.Name
End Sub


Then, in the popup:

Private Sub Form_Unload(Cancel As Integer)
Dim arrArg As Variant, strForm As Variant, strEval As String
arrArg = Split(Me.OpenArgs, "+")
strEval = "Forms"
For Each strForm In arrArg
strEval = strEval & "![" & strForm & "]"
Next strForm
strEval = strEval & "=" & Me.QuestionID
Eval (strEval)
End Sub

I get an error message from Access "A property of the Automation object
requires or returns a value that isn't supported by visual basic."

Obviously, there's got to be a way to reference a form when the full path to
it can be a variable length, but I'm durned if I know what it is. I tried
just passing a full on reference to the control in question, but access
didn't like the data type.


It might seem obvious to you that there's a way, but I think
you're wrong. At least I have never heard of how that
reference could be done.

The reason that Eval can't be used that wau is that it only
evaluates an expression and return the resulting value.

Anyway, false starts aside, the usual way to get the value
from a dialog form is for the dialog to make itself
invisible instead of closing. Then the calling form can
pull the result from it and close it.

DoCmd.OpenForm "Question Subform", , , _
WhereClause, , acDialog
Me.textbox = Forms("Question Subform").QuestionID
DoCmd.Close acForm,"Question Subform"
 
A

Amy Blankenship

OK, what's the correct syntax for the dialogue to make itself invisible?

Thanks;

Amy

Marshall Barton said:
Amy said:
I have a popup form I'd like to potentially call from more than one place.
So I'm trying to pass it the path to the calling subform and have it set a
control value on the calling form when it is closed. So what I have is
this:

in the calling form:

Private Sub LaunchQuestion_Click()
Dim WhereClause As String
If Me.QuestionID Is Not Null Then
WhereClause = "QuestionID = " + Me.QuestionID
Else
WhereClause = "IS NULL"
End If

DoCmd.OpenForm "Question Subform", , , WhereClause, , acDialog,
Me.Parent.Parent.Parent.Name + "+" + Me.Parent.Parent.Name + "+" +
Me.Parent.Name + "+" + Me.Name
Debug.Print Me.Parent.Parent.Name + "+" + Me.Parent.Name + "+" +
Me.Name
End Sub


Then, in the popup:

Private Sub Form_Unload(Cancel As Integer)
Dim arrArg As Variant, strForm As Variant, strEval As String
arrArg = Split(Me.OpenArgs, "+")
strEval = "Forms"
For Each strForm In arrArg
strEval = strEval & "![" & strForm & "]"
Next strForm
strEval = strEval & "=" & Me.QuestionID
Eval (strEval)
End Sub

I get an error message from Access "A property of the Automation object
requires or returns a value that isn't supported by visual basic."

Obviously, there's got to be a way to reference a form when the full path
to
it can be a variable length, but I'm durned if I know what it is. I tried
just passing a full on reference to the control in question, but access
didn't like the data type.


It might seem obvious to you that there's a way, but I think
you're wrong. At least I have never heard of how that
reference could be done.

The reason that Eval can't be used that wau is that it only
evaluates an expression and return the resulting value.

Anyway, false starts aside, the usual way to get the value
from a dialog form is for the dialog to make itself
invisible instead of closing. Then the calling form can
pull the result from it and close it.

DoCmd.OpenForm "Question Subform", , , _
WhereClause, , acDialog
Me.textbox = Forms("Question Subform").QuestionID
DoCmd.Close acForm,"Question Subform"
 
M

Marshall Barton

Gee, that's a tough one ;-)

Me.Visible = False
--
Marsh
MVP [MS Access]


Amy said:
OK, what's the correct syntax for the dialogue to make itself invisible?

Amy said:
I have a popup form I'd like to potentially call from more than one place.
So I'm trying to pass it the path to the calling subform and have it set a
control value on the calling form when it is closed. So what I have is
this:

in the calling form:

Private Sub LaunchQuestion_Click()
Dim WhereClause As String
If Me.QuestionID Is Not Null Then
WhereClause = "QuestionID = " + Me.QuestionID
Else
WhereClause = "IS NULL"
End If

DoCmd.OpenForm "Question Subform", , , WhereClause, , acDialog,
Me.Parent.Parent.Parent.Name + "+" + Me.Parent.Parent.Name + "+" +
Me.Parent.Name + "+" + Me.Name
Debug.Print Me.Parent.Parent.Name + "+" + Me.Parent.Name + "+" +
Me.Name
End Sub


Then, in the popup:

Private Sub Form_Unload(Cancel As Integer)
Dim arrArg As Variant, strForm As Variant, strEval As String
arrArg = Split(Me.OpenArgs, "+")
strEval = "Forms"
For Each strForm In arrArg
strEval = strEval & "![" & strForm & "]"
Next strForm
strEval = strEval & "=" & Me.QuestionID
Eval (strEval)
End Sub

I get an error message from Access "A property of the Automation object
requires or returns a value that isn't supported by visual basic."

Obviously, there's got to be a way to reference a form when the full path
to
it can be a variable length, but I'm durned if I know what it is. I tried
just passing a full on reference to the control in question, but access
didn't like the data type.

"Marshall Barton" wrote
It might seem obvious to you that there's a way, but I think
you're wrong. At least I have never heard of how that
reference could be done.

The reason that Eval can't be used that wau is that it only
evaluates an expression and return the resulting value.

Anyway, false starts aside, the usual way to get the value
from a dialog form is for the dialog to make itself
invisible instead of closing. Then the calling form can
pull the result from it and close it.

DoCmd.OpenForm "Question Subform", , , _
WhereClause, , acDialog
Me.textbox = Forms("Question Subform").QuestionID
DoCmd.Close acForm,"Question Subform"
 
A

Amy Blankenship

It was a bit more complicated, as it turns out, since you have to catch that
they closed the form and prevent it from completely closing...but only if
the user attempts to close it, not if the other form tries to close it,
because if you set cancel=true when you're trying to close from code, you
get an error.

You've been ever-so-slightly helpful anyway.

Thanks;

Amy

Marshall Barton said:
Gee, that's a tough one ;-)

Me.Visible = False
--
Marsh
MVP [MS Access]


Amy said:
OK, what's the correct syntax for the dialogue to make itself invisible?

Amy Blankenship wrote:
I have a popup form I'd like to potentially call from more than one
place.
So I'm trying to pass it the path to the calling subform and have it set
a
control value on the calling form when it is closed. So what I have is
this:

in the calling form:

Private Sub LaunchQuestion_Click()
Dim WhereClause As String
If Me.QuestionID Is Not Null Then
WhereClause = "QuestionID = " + Me.QuestionID
Else
WhereClause = "IS NULL"
End If

DoCmd.OpenForm "Question Subform", , , WhereClause, , acDialog,
Me.Parent.Parent.Parent.Name + "+" + Me.Parent.Parent.Name + "+" +
Me.Parent.Name + "+" + Me.Name
Debug.Print Me.Parent.Parent.Name + "+" + Me.Parent.Name + "+" +
Me.Name
End Sub


Then, in the popup:

Private Sub Form_Unload(Cancel As Integer)
Dim arrArg As Variant, strForm As Variant, strEval As String
arrArg = Split(Me.OpenArgs, "+")
strEval = "Forms"
For Each strForm In arrArg
strEval = strEval & "![" & strForm & "]"
Next strForm
strEval = strEval & "=" & Me.QuestionID
Eval (strEval)
End Sub

I get an error message from Access "A property of the Automation object
requires or returns a value that isn't supported by visual basic."

Obviously, there's got to be a way to reference a form when the full
path
to
it can be a variable length, but I'm durned if I know what it is. I
tried
just passing a full on reference to the control in question, but access
didn't like the data type.

"Marshall Barton" wrote
It might seem obvious to you that there's a way, but I think
you're wrong. At least I have never heard of how that
reference could be done.

The reason that Eval can't be used that wau is that it only
evaluates an expression and return the resulting value.

Anyway, false starts aside, the usual way to get the value
from a dialog form is for the dialog to make itself
invisible instead of closing. Then the calling form can
pull the result from it and close it.

DoCmd.OpenForm "Question Subform", , , _
WhereClause, , acDialog
Me.textbox = Forms("Question Subform").QuestionID
DoCmd.Close acForm,"Question Subform"
 
M

Marshall Barton

Sorry, I didn't realize you still needed that part. One key
to this whole arrangement is to set the dialog form's
BorderStyle to Dialog and ControlBox to No so there are no
buttons in the title bar for the user to close it. The
form's OK (or whatever) button just makes the form
invisible. This is normally all you the code you should
have for the button:

Private Sub btnOK_Click()
Me.Visible = False
End Sub

Unless you have something tricky going on that I haven't
picked up on, there's no need to cancel the unload event.
Actually you probably don't need the Unload event at all.

OTOH, if you really do have a requirement to prevent the
user from trying to close the form through some outside
mechanism, the relevant code in the dialog form could be
something like:

Dim bolClose As Boolean

Private Sub btnOK_Click()
bolClose = True
Me.Visible = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
If Not bolClose Then
Beep
Cancel = True
End If
End Sub
--
Marsh
MVP [MS Access]


Amy said:
It was a bit more complicated, as it turns out, since you have to catch that
they closed the form and prevent it from completely closing...but only if
the user attempts to close it, not if the other form tries to close it,
because if you set cancel=true when you're trying to close from code, you
get an error.


Gee, that's a tough one ;-)

Me.Visible = False


Amy said:
OK, what's the correct syntax for the dialogue to make itself invisible?


Amy Blankenship wrote:
I have a popup form I'd like to potentially call from more than one
place.
So I'm trying to pass it the path to the calling subform and have it set
a
control value on the calling form when it is closed. So what I have is
this:

in the calling form:

Private Sub LaunchQuestion_Click()
Dim WhereClause As String
If Me.QuestionID Is Not Null Then
WhereClause = "QuestionID = " + Me.QuestionID
Else
WhereClause = "IS NULL"
End If

DoCmd.OpenForm "Question Subform", , , WhereClause, , acDialog,
Me.Parent.Parent.Parent.Name + "+" + Me.Parent.Parent.Name + "+" +
Me.Parent.Name + "+" + Me.Name
Debug.Print Me.Parent.Parent.Name + "+" + Me.Parent.Name + "+" +
Me.Name
End Sub


Then, in the popup:

Private Sub Form_Unload(Cancel As Integer)
Dim arrArg As Variant, strForm As Variant, strEval As String
arrArg = Split(Me.OpenArgs, "+")
strEval = "Forms"
For Each strForm In arrArg
strEval = strEval & "![" & strForm & "]"
Next strForm
strEval = strEval & "=" & Me.QuestionID
Eval (strEval)
End Sub

I get an error message from Access "A property of the Automation object
requires or returns a value that isn't supported by visual basic."

Obviously, there's got to be a way to reference a form when the full
path
to
it can be a variable length, but I'm durned if I know what it is. I
tried
just passing a full on reference to the control in question, but access
didn't like the data type.


It might seem obvious to you that there's a way, but I think
you're wrong. At least I have never heard of how that
reference could be done.

The reason that Eval can't be used that wau is that it only
evaluates an expression and return the resulting value.

Anyway, false starts aside, the usual way to get the value
from a dialog form is for the dialog to make itself
invisible instead of closing. Then the calling form can
pull the result from it and close it.

DoCmd.OpenForm "Question Subform", , , _
WhereClause, , acDialog
Me.textbox = Forms("Question Subform").QuestionID
DoCmd.Close acForm,"Question Subform"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top