SilverBean
Programmer
I've got a good amount of VB knowledge mainly started with VB 4, alot of work with VB 5, a
little with 6.
As I work with Access 2002, I see alot that is the same from VB and alot
that is different; hence the name VBA.
I checked out some previous posts on scoping and I came up with Global which
I don't recall playing with before. I wasn't able to check if the impact on my observations below.
Anyway what I'm trying to do is to get information from a Form down to a
child on that form in order for the child to add or edit its particular
source (another table in this instance). By the way I do have Automatic
Variable declaration turned off and I'm aware of that effect on the code I
write.
So in the parent form I have in the General Declarations:
Option Compare Database
Public VariableForChild as String
and when needed I put something in it that I want the child to have. I do
this in the PARENT for example on a button click.
Private Sub SomeButton_Click()
VariableForChild = 2
Sub End
Now when the child needs to put that information in the table I do a
Private Sub Form_BeforeUpdate(Cancel as Integer)
[FID] = Form_Parent.VariableForChild
End Sub
Ok, so it does work HOWEVER, it does not work all time. Specifically I've
traced it down to the initial time that this portion is executed. It seems
my Form_Parent.VariableForChild never gets intializied its Null and the
Update barfs on that. However, I've traced through displayed status Message
Boxes and after the first time subsequent "adds" let's call it are fine the
right variable gets put in FID. I have tried [FID].Value and that was no
help.
Its almost like in the Click event the VariableForChild and
Form_Parent.VariableForChild are different, however if I remove the Public
declaration the click events barfs because VariableForChild
undefined.....very interesting. In the button click event if I use
Form_Parent.VariableForChild = 2 that works fine all the time. That seems a
little redundant overkill - I'd like to have a reason as to what the correct
syntax is here. Me.VariableForChild = 2 is very attractive I could live with
that but why? Obviously VB something knows its the same variable, object
whatever?
Questions are: Once again what I'm trying to do is get some data from a Form
down to its child so that the child can put it into a table. Its really not
possible for a link(on this data) - not sure if that would even help.
Q1. Whats wrong with the above? If my VB memory serves everything above is
fine and it does work.
Q2. Any suggestions on a VBA-safe way to do this?
little with 6.
As I work with Access 2002, I see alot that is the same from VB and alot
that is different; hence the name VBA.
I checked out some previous posts on scoping and I came up with Global which
I don't recall playing with before. I wasn't able to check if the impact on my observations below.
Anyway what I'm trying to do is to get information from a Form down to a
child on that form in order for the child to add or edit its particular
source (another table in this instance). By the way I do have Automatic
Variable declaration turned off and I'm aware of that effect on the code I
write.
So in the parent form I have in the General Declarations:
Option Compare Database
Public VariableForChild as String
and when needed I put something in it that I want the child to have. I do
this in the PARENT for example on a button click.
Private Sub SomeButton_Click()
VariableForChild = 2
Sub End
Now when the child needs to put that information in the table I do a
Private Sub Form_BeforeUpdate(Cancel as Integer)
[FID] = Form_Parent.VariableForChild
End Sub
Ok, so it does work HOWEVER, it does not work all time. Specifically I've
traced it down to the initial time that this portion is executed. It seems
my Form_Parent.VariableForChild never gets intializied its Null and the
Update barfs on that. However, I've traced through displayed status Message
Boxes and after the first time subsequent "adds" let's call it are fine the
right variable gets put in FID. I have tried [FID].Value and that was no
help.
Its almost like in the Click event the VariableForChild and
Form_Parent.VariableForChild are different, however if I remove the Public
declaration the click events barfs because VariableForChild
undefined.....very interesting. In the button click event if I use
Form_Parent.VariableForChild = 2 that works fine all the time. That seems a
little redundant overkill - I'd like to have a reason as to what the correct
syntax is here. Me.VariableForChild = 2 is very attractive I could live with
that but why? Obviously VB something knows its the same variable, object
whatever?
Questions are: Once again what I'm trying to do is get some data from a Form
down to its child so that the child can put it into a table. Its really not
possible for a link(on this data) - not sure if that would even help.
Q1. Whats wrong with the above? If my VB memory serves everything above is
fine and it does work.
Q2. Any suggestions on a VBA-safe way to do this?