Go to a form and fill in a field

S

sweyer

I have a form that I created that is to add a new employee to our database.
We deal with insurance, so I want to be able to add a dependant to that
person's record. I have a form for new employee and a form for new dependent.
Once a person has filled in the new employee information, they should click
on a button that says add dependent. When the add dependent form opens, I
want the parent information to be automatically filled in.

For example, I have 2 tables: EmployeeInfo and DependentInfo. The
DependentInfo has a field called DependentOfSSN which is linked to the SSN
field in EmployeeInfo. When you add a new employee, you have to fill in SSN,
and when you go to the add dependent form, I want the field DependentOfSSN to
be automatically filled in with the SSN from the new employee screen.

Can anyone help me with this?

Thank you!
 
J

Jayyde

I'm sure there's a more efficient way of doing it, but I simply made a
global module and put a bunch of SetInfo() and GetInfo() function inside it.
Set them in the parent, and get them in the child.

hth
-Jayyde
 
S

sweyer

I'm still somewhat of a newbie to Access, so I need a little more info. I
don't know much about the SQL coding, so I need some more direction. Where do
I put SetInfo() and GetInfo() and how do I use it?
I'm sure there's a more efficient way of doing it, but I simply made a
global module and put a bunch of SetInfo() and GetInfo() function inside it.
Set them in the parent, and get them in the child.

hth
-Jayyde
I have a form that I created that is to add a new employee to our database.
We deal with insurance, so I want to be able to add a dependant to that
[quoted text clipped - 16 lines]
Thank you!
 
J

Jayyde

It's acutally in the VBA code. If you go to Modules then New. Add code like

****in the new module***
Dim strSSN as string

Public Sub SetSSN (ssn as string)
strSSN = ssn
End Sub

Public Function GetSSN () as string
GetSSN = strSSN
End Function

****in the parent form***
[nameOfModule].SetSSN([txtssn])

****in the child form***
[txtssn] = [nameOfModule].GetSSN

for each field you're trying to share in between the 2 forms. I'd put the
Set stuff in the click event for whatever button opens the child (but before
you actually open the child form) and the Get stuff in the child's open
event.

hth
-Jayyde

sweyer said:
I'm still somewhat of a newbie to Access, so I need a little more info. I
don't know much about the SQL coding, so I need some more direction. Where
do
I put SetInfo() and GetInfo() and how do I use it?
I'm sure there's a more efficient way of doing it, but I simply made a
global module and put a bunch of SetInfo() and GetInfo() function inside
it.
Set them in the parent, and get them in the child.

hth
-Jayyde
I have a form that I created that is to add a new employee to our
database.
We deal with insurance, so I want to be able to add a dependant to that
[quoted text clipped - 16 lines]
Thank you!
 
S

sweyer

Okay I did that, but I get an error when I try to execute it. I get a VB
error that says:

Run-time error '-2147352567 (80020009)':
You can't assign a value to this object.

When I hit debug, it brings me to the child form's code in the section that
says:

Private Sub Form_Open(Cancel As Integer)
[ParentSSN] = [SSNModule].GetSSN
End Sub

ParentSSN is the name of the SSN field on the child form, and SSNModule is
the module I created.

Where did I go wrong?

I was thinking that I needed a () right after the GetSSN, but that didn't
work either.
It's acutally in the VBA code. If you go to Modules then New. Add code like

****in the new module***
Dim strSSN as string

Public Sub SetSSN (ssn as string)
strSSN = ssn
End Sub

Public Function GetSSN () as string
GetSSN = strSSN
End Function

****in the parent form***
[nameOfModule].SetSSN([txtssn])

****in the child form***
[txtssn] = [nameOfModule].GetSSN

for each field you're trying to share in between the 2 forms. I'd put the
Set stuff in the click event for whatever button opens the child (but before
you actually open the child form) and the Get stuff in the child's open
event.

hth
-Jayyde
I'm still somewhat of a newbie to Access, so I need a little more info. I
don't know much about the SQL coding, so I need some more direction. Where
[quoted text clipped - 15 lines]
 
J

Jayyde

If it's going into a text box put the name of that instead of ParentSSN.
Oh, and you shouldn't really need the brackets, I just put them there for
readability =).
Like

txtParentSSN = SSNModule.GetSSN

hth
-Jayyde

sweyer said:
Okay I did that, but I get an error when I try to execute it. I get a VB
error that says:

Run-time error '-2147352567 (80020009)':
You can't assign a value to this object.

When I hit debug, it brings me to the child form's code in the section
that
says:

Private Sub Form_Open(Cancel As Integer)
[ParentSSN] = [SSNModule].GetSSN
End Sub

ParentSSN is the name of the SSN field on the child form, and SSNModule is
the module I created.

Where did I go wrong?

I was thinking that I needed a () right after the GetSSN, but that didn't
work either.
It's acutally in the VBA code. If you go to Modules then New. Add code
like

****in the new module***
Dim strSSN as string

Public Sub SetSSN (ssn as string)
strSSN = ssn
End Sub

Public Function GetSSN () as string
GetSSN = strSSN
End Function

****in the parent form***
[nameOfModule].SetSSN([txtssn])

****in the child form***
[txtssn] = [nameOfModule].GetSSN

for each field you're trying to share in between the 2 forms. I'd put the
Set stuff in the click event for whatever button opens the child (but
before
you actually open the child form) and the Get stuff in the child's open
event.

hth
-Jayyde
I'm still somewhat of a newbie to Access, so I need a little more info.
I
don't know much about the SQL coding, so I need some more direction.
Where
[quoted text clipped - 15 lines]
Thank you!
 
S

sweyer

I still can't get it to work.....the form is opening in Add mode, does that
make a difference?
If it's going into a text box put the name of that instead of ParentSSN.
Oh, and you shouldn't really need the brackets, I just put them there for
readability =).
Like

txtParentSSN = SSNModule.GetSSN

hth
-Jayyde
Okay I did that, but I get an error when I try to execute it. I get a VB
error that says:
[quoted text clipped - 54 lines]
 
J

Jayyde

Shouldn't. Unless in form current you're resetting the text box to empty or
something. What's the code? and is it still throwing an error?

sweyer said:
I still can't get it to work.....the form is opening in Add mode, does that
make a difference?
If it's going into a text box put the name of that instead of ParentSSN.
Oh, and you shouldn't really need the brackets, I just put them there for
readability =).
Like

txtParentSSN = SSNModule.GetSSN

hth
-Jayyde
Okay I did that, but I get an error when I try to execute it. I get a
VB
error that says:
[quoted text clipped - 54 lines]
Thank you!
 
S

sweyer

This is the code for the button on the parent form:

Private Sub Command65_Click()
On Error GoTo Err_Command65_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "NewDependent"
[SSNModule].SetSSN ([SSN])
DoCmd.OpenForm stDocName, DataMode:=acFormAdd


Exit_Command65_Click:
Exit Sub

Err_Command65_Click:
MsgBox Err.Description
Resume Exit_Command65_Click

End Sub



And this is the code for the child form (on open):

Private Sub Form_Open(Cancel As Integer)
txtParentSSN = SSNModule.GetSSN
End Sub


In the parent form, Command65 is the button name (yea I know I should rename
it, I'll do that later) and SSN is the parent's SSN number (same name of the
field in the table that this form is connected to - not the same table as the
child form).

In the child form, ParentSSN is the name of the text box that holds the value
of ParentSSN, which is the name of the field in the table this is connected
to.
Shouldn't. Unless in form current you're resetting the text box to empty or
something. What's the code? and is it still throwing an error?
I still can't get it to work.....the form is opening in Add mode, does that
make a difference?
[quoted text clipped - 15 lines]
 
J

Jayyde

Take out all the [ ]'s (in the module too if they're there). Didn't mean to
twist you up with them. And no worries, I don't always name my stuff right
away either =)

hth
-Jayyde

sweyer said:
This is the code for the button on the parent form:

Private Sub Command65_Click()
On Error GoTo Err_Command65_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "NewDependent"
[SSNModule].SetSSN ([SSN])
DoCmd.OpenForm stDocName, DataMode:=acFormAdd


Exit_Command65_Click:
Exit Sub

Err_Command65_Click:
MsgBox Err.Description
Resume Exit_Command65_Click

End Sub



And this is the code for the child form (on open):

Private Sub Form_Open(Cancel As Integer)
txtParentSSN = SSNModule.GetSSN
End Sub


In the parent form, Command65 is the button name (yea I know I should
rename
it, I'll do that later) and SSN is the parent's SSN number (same name of
the
field in the table that this form is connected to - not the same table as
the
child form).

In the child form, ParentSSN is the name of the text box that holds the
value
of ParentSSN, which is the name of the field in the table this is
connected
to.
Shouldn't. Unless in form current you're resetting the text box to empty
or
something. What's the code? and is it still throwing an error?
I still can't get it to work.....the form is opening in Add mode, does
that
make a difference?
[quoted text clipped - 15 lines]
Thank you!
 
S

sweyer

Oh and it's not giving me an error. It's just opening the form, but not
filling in the text box.
Shouldn't. Unless in form current you're resetting the text box to empty or
something. What's the code? and is it still throwing an error?
I still can't get it to work.....the form is opening in Add mode, does that
make a difference?
[quoted text clipped - 15 lines]
 
S

sweyer

Nope....still not working. I usually don't have a problem with the [ ]'s, so
I din't think that would have been the cause. Well, I'm done for the day. If
you think of anything else that could cause this to not be working, post it
and I'll check again when I get back in the office on Friday. (I'm off
tomorrow).

Thanks for your help!
Take out all the [ ]'s (in the module too if they're there). Didn't mean to
twist you up with them. And no worries, I don't always name my stuff right
away either =)

hth
-Jayyde
This is the code for the button on the parent form:
[quoted text clipped - 47 lines]
 
J

Jayyde

Hm. I'm assuming that in that global module the SSN string that you're
getting and setting is Dim-ed at the top, right?

sweyer said:
Oh and it's not giving me an error. It's just opening the form, but not
filling in the text box.
Shouldn't. Unless in form current you're resetting the text box to empty
or
something. What's the code? and is it still throwing an error?
I still can't get it to work.....the form is opening in Add mode, does
that
make a difference?
[quoted text clipped - 15 lines]
Thank you!
 
S

sweyer via AccessMonster.com

I guess....this is that the global module says:

Dim strSSN As String

Public Sub SetSSN(SSN As String)
strSSN = SSN
End Sub

Public Function GetSSN() As String
GetSSN = strSSN
End Function

Hm. I'm assuming that in that global module the SSN string that you're
getting and setting is Dim-ed at the top, right?
Oh and it's not giving me an error. It's just opening the form, but not
filling in the text box.
[quoted text clipped - 9 lines]
 
J

Jayyde

Try putting it into form_current instead, it might be the data mode =
acformadd (i didn't do that in mine).

sweyer said:
Nope....still not working. I usually don't have a problem with the [ ]'s,
so
I din't think that would have been the cause. Well, I'm done for the day.
If
you think of anything else that could cause this to not be working, post
it
and I'll check again when I get back in the office on Friday. (I'm off
tomorrow).

Thanks for your help!
Take out all the [ ]'s (in the module too if they're there). Didn't mean
to
twist you up with them. And no worries, I don't always name my stuff
right
away either =)

hth
-Jayyde
This is the code for the button on the parent form:
[quoted text clipped - 47 lines]
Thank you!
 

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