Automaticaly fill in fields

C

Cameron Piper

I am working on a database in Access 2002 with a windows
and office XP Pro based machine. I have what seems like
a real simple question, but I just haven't been able to
figure it out.

I would like to open a pop-up form and have certain
fields filled in automatically. My google searches have
been littered with how to do this if you are opening
another copy of the same form and you want to copy some
of the fields, but I have yet to find the answer if you
are opening a different form with a different record
source even.

I have two forms linked to two different tables.
tblClient is linked to tblActivity with a field called
ClientID. From frmClient(record source = tblclient), I
would like to be able to click a button and open a "new
activity record," but have the clientID the same as the
primary form. Essentialy I would like to create a new
activity for that client. I tried the following codes to
attempt to accomplish this.

1. linking the fields with a link criteria like so:

stLinkCriteria = "[ClientID]=" & Me![ClientID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

However, I found that this code will open a form and find
an existing activity where the clientID matches.

2. This code however gave me error 2448:
stLinkCriteria = "[ClientID]=" & Me![ClientID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec

Me!ClientID = Forms![frmClient].[ClientID]


I am assuming that I will need to use:

DoCmd.GoToRecord , , acNewRec

to get to the new record but I need to know how to set
the values in the new record to match the previous form.

Can anyone help me along to be able to set these values?
Thank you in advance for your help.

Cameron Piper
CSPiper).Please.No.Spam(@CBBurnet(.Thank.You).com
 
G

Guest

Hi Cameron,

One way would be to pass the [ClientID] in the "openargs"
argument when opening the form and then setting the new
forms clientID = me.openargs in the open event.

DoCmd.OpenForm stDocName, , , , , , Me.ClientID

Then in the open event procedure

DoCmd.GoToRecord , , acNewRec
me.clientID = me.openargs

Glenn.
 
G

Glenn

Cameron,

If the previous form is still open you can set the values
of as many fields as you wish in the on open event of the
new form:

DoCmd.GoToRecord , , acNewRec

Me.ClientID = Forms!Forms![frmClient].[ClientID]
Me.AnotherField = Forms![frmClient].[AnotherField]

Etc.

Glenn

-----Original Message-----
Hi Cameron,

One way would be to pass the [ClientID] in the "openargs"
argument when opening the form and then setting the new
forms clientID = me.openargs in the open event.

DoCmd.OpenForm stDocName, , , , , , Me.ClientID

Then in the open event procedure

DoCmd.GoToRecord , , acNewRec
me.clientID = me.openargs

Glenn.
-----Original Message-----
I am working on a database in Access 2002 with a windows
and office XP Pro based machine. I have what seems like
a real simple question, but I just haven't been able to
figure it out.

I would like to open a pop-up form and have certain
fields filled in automatically. My google searches have
been littered with how to do this if you are opening
another copy of the same form and you want to copy some
of the fields, but I have yet to find the answer if you
are opening a different form with a different record
source even.

I have two forms linked to two different tables.
tblClient is linked to tblActivity with a field called
ClientID. From frmClient(record source = tblclient), I
would like to be able to click a button and open a "new
activity record," but have the clientID the same as the
primary form. Essentialy I would like to create a new
activity for that client. I tried the following codes to
attempt to accomplish this.

1. linking the fields with a link criteria like so:

stLinkCriteria = "[ClientID]=" & Me![ClientID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

However, I found that this code will open a form and find
an existing activity where the clientID matches.

2. This code however gave me error 2448:
stLinkCriteria = "[ClientID]=" & Me![ClientID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec

Me!ClientID = Forms![frmClient].[ClientID]


I am assuming that I will need to use:

DoCmd.GoToRecord , , acNewRec

to get to the new record but I need to know how to set
the values in the new record to match the previous form.

Can anyone help me along to be able to set these values?
Thank you in advance for your help.

Cameron Piper
CSPiper).Please.No.Spam(@CBBurnet(.Thank.You).com
.
.
 
G

Glenn

OK Cameron,

Use a mix of the solutions:

Use the openargs argument when you want to go to the new
record and then in the on open event only go to the new
record and populate the fields if the openargs = "X":

if me.openArgs = "X" then
DoCmd.GoToRecord , , acNewRec

Me.ClientID = Forms!Forms![frmClient].[ClientID]
Me.AnotherField = Forms![frmClient].[AnotherField]
end if

Glenn.
-----Original Message-----
-----Original Message-----
Cameron,

If the previous form is still open you can set the values
of as many fields as you wish in the on open event of the
new form:

DoCmd.GoToRecord , , acNewRec

Me.ClientID = Forms!Forms![frmClient].[ClientID]
Me.AnotherField = Forms![frmClient].[AnotherField]

Etc.

Glenn

-----Original Message-----
Hi Cameron,

One way would be to pass the [ClientID] in the "openargs"
argument when opening the form and then setting the new
forms clientID = me.openargs in the open event.

DoCmd.OpenForm stDocName, , , , , , Me.ClientID

Then in the open event procedure

DoCmd.GoToRecord , , acNewRec
me.clientID = me.openargs

Glenn.

-----Original Message-----
I am working on a database in Access 2002 with a windows
and office XP Pro based machine. I have what seems like
a real simple question, but I just haven't been able to
figure it out.

I would like to open a pop-up form and have certain
fields filled in automatically. My google searches have
been littered with how to do this if you are opening
another copy of the same form and you want to copy some
of the fields, but I have yet to find the answer if you
are opening a different form with a different record
source even.

I have two forms linked to two different tables.
tblClient is linked to tblActivity with a field called
ClientID. From frmClient(record source = tblclient), I
would like to be able to click a button and open a "new
activity record," but have the clientID the same as the
primary form. Essentialy I would like to create a new
activity for that client. I tried the following codes to
attempt to accomplish this.

1. linking the fields with a link criteria like so:

stLinkCriteria = "[ClientID]=" & Me![ClientID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

However, I found that this code will open a form and find
an existing activity where the clientID matches.

2. This code however gave me error 2448:
stLinkCriteria = "[ClientID]=" & Me![ClientID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec

Me!ClientID = Forms![frmClient].[ClientID]


I am assuming that I will need to use:

DoCmd.GoToRecord , , acNewRec

to get to the new record but I need to know how to set
the values in the new record to match the previous form.

Can anyone help me along to be able to set these values?
Thank you in advance for your help.

Cameron Piper
CSPiper).Please.No.Spam(@CBBurnet(.Thank.You).com

Glenn,

Thank you very much for your help on the matter thus
far. The trouble I am having is that the form that I am
opening is used in other places as well. At times it is
used to simple call up a specific task. (The new record
command in the open event would cause this previous
application not to work) Any thoughts. I know that I
could create an entirely new form for this but I feel
that that would be redundant and would add unnecessary
size to the database. Once again thank you for your help.

Cameron
.
 
C

Cameron

-----Original Message-----
OK Cameron,

Use a mix of the solutions:

Use the openargs argument when you want to go to the new
record and then in the on open event only go to the new
record and populate the fields if the openargs = "X":

if me.openArgs = "X" then
DoCmd.GoToRecord , , acNewRec

Me.ClientID = Forms!Forms![frmClient].[ClientID]
Me.AnotherField = Forms![frmClient]. [AnotherField]
end if

Glenn.
-----Original Message-----
-----Original Message-----
Cameron,

If the previous form is still open you can set the values
of as many fields as you wish in the on open event of the
new form:

DoCmd.GoToRecord , , acNewRec

Me.ClientID = Forms!Forms![frmClient].[ClientID]
Me.AnotherField = Forms![frmClient].[AnotherField]

Etc.

Glenn


-----Original Message-----
Hi Cameron,

One way would be to pass the [ClientID] in the "openargs"
argument when opening the form and then setting the new
forms clientID = me.openargs in the open event.

DoCmd.OpenForm stDocName, , , , , , Me.ClientID

Then in the open event procedure

DoCmd.GoToRecord , , acNewRec
me.clientID = me.openargs

Glenn.

-----Original Message-----
I am working on a database in Access 2002 with a windows
and office XP Pro based machine. I have what seems like
a real simple question, but I just haven't been able to
figure it out.

I would like to open a pop-up form and have certain
fields filled in automatically. My google searches have
been littered with how to do this if you are opening
another copy of the same form and you want to copy some
of the fields, but I have yet to find the answer if you
are opening a different form with a different record
source even.

I have two forms linked to two different tables.
tblClient is linked to tblActivity with a field called
ClientID. From frmClient(record source =
tblclient),
I
would like to be able to click a button and open a "new
activity record," but have the clientID the same as the
primary form. Essentialy I would like to create a new
activity for that client. I tried the following codes
to
attempt to accomplish this.

1. linking the fields with a link criteria like so:

stLinkCriteria = "[ClientID]=" & Me![ClientID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

However, I found that this code will open a form and
find
an existing activity where the clientID matches.

2. This code however gave me error 2448:
stLinkCriteria = "[ClientID]=" & Me![ClientID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec

Me!ClientID = Forms![frmClient].[ClientID]


I am assuming that I will need to use:

DoCmd.GoToRecord , , acNewRec

to get to the new record but I need to know how to set
the values in the new record to match the previous form.

Can anyone help me along to be able to set these values?
Thank you in advance for your help.

Cameron Piper
CSPiper).Please.No.Spam(@CBBurnet(.Thank.You).com

Glenn,

Thank you very much for your help on the matter thus
far. The trouble I am having is that the form that I am
opening is used in other places as well. At times it is
used to simple call up a specific task. (The new record
command in the open event would cause this previous
application not to work) Any thoughts. I know that I
could create an entirely new form for this but I feel
that that would be redundant and would add unnecessary
size to the database. Once again thank you for your help.

Cameron

Glenn or someone else,

I feel like I am almost there but I need your help again.
I switched forms but would like to accomplish the same
type of thing on these two forms. I put the following
code in the click event of a button on frmTransaction:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmActivity"

DoCmd.OpenForm stDocName, , , , , , Me.DateClose &
Me.ClientID

I then put the following code in the open event of
frmActivity:


If Me.OpenArgs = "X" Then

DoCmd.GoToRecord , , acNewRec

Me.ClientID = Forms![frmTransaction].[ClientID]
Me.DateDue = Forms![frmTransaction].DateClose

End If

I also tried:

"If Me.OpenArgs = True Then"

But both opened up a random activity that has already
been filled out.

If I remove the "If" statements, the function works
perfectly. However, I get an error if I try to open the
form from anywhere else (as expected). Can you help with
the if statment so that this will work properly? Exact
syntax would help so that I can't possibly screw it up
again.

Thank you for your time and your patience.
 
G

Glenn

Cameron,

It's my fault for not being specific. The openargs value
can be anything you want it to be when sending. I would
personally use something like "TransactionForm" so it has
some meaning:

DoCmd.OpenForm stDocName, , , , , , "TransactionForm"

Then in the on open event of the other form you check for
the value you sent:

If Me.OpenArgs = "TransactionForm" Then

DoCmd.GoToRecord , , acNewRec

Me.ClientID = Forms![frmTransaction].[ClientID]
Me.DateDue = Forms![frmTransaction].DateClose

End If

This way the If statement will only trigger when the form
has been opened from the Transaction Form's calling
statement.

Rgds,
Glenn.
-----Original Message-----
-----Original Message-----
OK Cameron,

Use a mix of the solutions:

Use the openargs argument when you want to go to the new
record and then in the on open event only go to the new
record and populate the fields if the openargs = "X":

if me.openArgs = "X" then
DoCmd.GoToRecord , , acNewRec

Me.ClientID = Forms!Forms![frmClient].[ClientID]
Me.AnotherField = Forms![frmClient]. [AnotherField]
end if

Glenn.
-----Original Message-----

-----Original Message-----
Cameron,

If the previous form is still open you can set the
values
of as many fields as you wish in the on open event of
the
new form:

DoCmd.GoToRecord , , acNewRec

Me.ClientID = Forms!Forms![frmClient].[ClientID]
Me.AnotherField = Forms![frmClient].[AnotherField]

Etc.

Glenn


-----Original Message-----
Hi Cameron,

One way would be to pass the [ClientID] in
the "openargs"
argument when opening the form and then setting the new
forms clientID = me.openargs in the open event.

DoCmd.OpenForm stDocName, , , , , , Me.ClientID

Then in the open event procedure

DoCmd.GoToRecord , , acNewRec
me.clientID = me.openargs

Glenn.

-----Original Message-----
I am working on a database in Access 2002 with a
windows
and office XP Pro based machine. I have what seems
like
a real simple question, but I just haven't been able
to
figure it out.

I would like to open a pop-up form and have certain
fields filled in automatically. My google searches
have
been littered with how to do this if you are opening
another copy of the same form and you want to copy
some
of the fields, but I have yet to find the answer if
you
are opening a different form with a different record
source even.

I have two forms linked to two different tables.
tblClient is linked to tblActivity with a field called
ClientID. From frmClient(record source = tblclient),
I
would like to be able to click a button and open
a "new
activity record," but have the clientID the same as
the
primary form. Essentialy I would like to create a new
activity for that client. I tried the following codes
to
attempt to accomplish this.

1. linking the fields with a link criteria like so:

stLinkCriteria = "[ClientID]=" & Me![ClientID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

However, I found that this code will open a form and
find
an existing activity where the clientID matches.

2. This code however gave me error 2448:
stLinkCriteria = "[ClientID]=" & Me![ClientID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.GoToRecord , , acNewRec

Me!ClientID = Forms![frmClient].[ClientID]


I am assuming that I will need to use:

DoCmd.GoToRecord , , acNewRec

to get to the new record but I need to know how to set
the values in the new record to match the previous
form.

Can anyone help me along to be able to set these
values?
Thank you in advance for your help.

Cameron Piper
CSPiper).Please.No.Spam(@CBBurnet(.Thank.You).com

Glenn,

Thank you very much for your help on the matter thus
far. The trouble I am having is that the form that I am
opening is used in other places as well. At times it is
used to simple call up a specific task. (The new record
command in the open event would cause this previous
application not to work) Any thoughts. I know that I
could create an entirely new form for this but I feel
that that would be redundant and would add unnecessary
size to the database. Once again thank you for your help.

Cameron

Glenn or someone else,

I feel like I am almost there but I need your help again.
I switched forms but would like to accomplish the same
type of thing on these two forms. I put the following
code in the click event of a button on frmTransaction:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmActivity"

DoCmd.OpenForm stDocName, , , , , , Me.DateClose &
Me.ClientID

I then put the following code in the open event of
frmActivity:


If Me.OpenArgs = "X" Then

DoCmd.GoToRecord , , acNewRec

Me.ClientID = Forms![frmTransaction].[ClientID]
Me.DateDue = Forms![frmTransaction].DateClose

End If

I also tried:

"If Me.OpenArgs = True Then"

But both opened up a random activity that has already
been filled out.

If I remove the "If" statements, the function works
perfectly. However, I get an error if I try to open the
form from anywhere else (as expected). Can you help with
the if statment so that this will work properly? Exact
syntax would help so that I can't possibly screw it up
again.

Thank you for your time and your patience.


.
 

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