Populate field based on previous form

B

Ben Pelech

Hello,

In a form the employee selects their name and their manager name from a drop
down list. Is there a way for those values to repeat themselves for that
user based on the first form they fill out for the day.

Ie. They select their name and their manager's name from a drop down. When
they are done with that form they add a new form. Can that new form remember
their selection from the previous form and automatically fill it out so they
dont have to keep selecting their name?

Thanks for your help!!

Ben
 
J

John W. Vinson/MVP

Ie. They select their name and their manager's name from a drop down. When
they are done with that form they add a new form. Can that new form remember
their selection from the previous form and automatically fill it out so they
dont have to keep selecting their name?

Yes. You can set the DefaultValue property of the combo box in its own
AfterUpdate event. Select the control (cboManager let's say it's
called) and view its Properties. On the Events tab find the
AfterUpdate event, and click the ... icon; choose Code Builder and
edit it to

Private Sub cboManager_AfterUpdate() <<< Access gives you this
Me!cboManager.DefaultValue = """" & Me!cboManager & """"
End Sub

The four quotemarks are what you need to insert a single quotemark
before and after the value.
 
B

Ben Pelech

Getting an error message. Did I take your code to literal?

Private Sub Customer_Care_Agent_AfterUpdate()
Me!Customer_Care_Agent.DefaultValue = """" & Me!Customer_Care_Agent & """"
End Sub
 
J

John W. Vinson/MVP

Getting an error message. Did I take your code to literal?

Private Sub Customer_Care_Agent_AfterUpdate()
Me!Customer_Care_Agent.DefaultValue = """" & Me!Customer_Care_Agent & """"
End Sub

Care to tell us WHAT error message? Is the name of the control in fact
Customer_Care_Agent? If it's a Combo Box, what are its RowSource and
Control Source properties?
 
B

Ben Pelech

These are all actually users of the database. is there an easier way to just
populate their name based on their user ID? or is this the easiest way.. to
have them fill in the first form and it carry through the rest of the records
they complete that day!!

Thanks again for your help!!
 
B

Ben Pelech

Hello,

Sorry. The error message says Run time error 2465 Microsoft access cant find
the field Customer_Care_Agent referred to in your expression. So I tried to
do it without the underscores and it gave me a syntax error.

It is a combobox. The control source is Customer Care Agent and the row
source is SELECT TblCCAgents.Field1 FROM TblCCAgents ORDER BY
TblCCAgents.Field1;

Thanks!!!
 
J

John W. Vinson/MVP

These are all actually users of the database. is there an easier way to just
populate their name based on their user ID? or is this the easiest way.. to
have them fill in the first form and it carry through the rest of the records
they complete that day!!

Thanks again for your help!!

Which "user ID"? Do you have Access security enabled and require
individual logons, or do you mean the Windows ID?

My default value suggestion will indeed set the default value of the
field to the most recent entry. If the user enters the data and then
leaves the form open all day, it will retain that default value.
 
B

Ben Pelech

Sorry not sure if you saw my response that I sent before you responded to my
other one.

Hello,

Sorry. The error message says Run time error 2465 Microsoft access cant find
the field Customer_Care_Agent referred to in your expression. So I tried to
do it without the underscores and it gave me a syntax error.

It is a combobox. The control source is Customer Care Agent and the row
source is SELECT TblCCAgents.Field1 FROM TblCCAgents ORDER BY
TblCCAgents.Field1;

Thanks!!!
 
J

John W. Vinson/MVP

Hello,

Sorry. The error message says Run time error 2465 Microsoft access cant find
the field Customer_Care_Agent referred to in your expression. So I tried to
do it without the underscores and it gave me a syntax error.

It is a combobox. The control source is Customer Care Agent and the row
source is SELECT TblCCAgents.Field1 FROM TblCCAgents ORDER BY
TblCCAgents.Field1;

I'm guessing that the name of the control is (unwisely, blanks cause
problems in control and fieldnames) actually "Customer Care Agent". If
so, Access will insert the underscores in the sub name, but you need
to use square brackets in the code:

Private Sub Customer_Care_Agent_AfterUpdate()
Me![Customer Care Agent].DefaultValue = """" & Me![Customer Care
Agent] & """"
End Sub

Be sure the Me!... code is all on one line (it's word wrapping in the
newsgroup).
 
B

Ben Pelech

Works perfectly. Thank you so much. I dont know what I would do without you
guys!!!

John W. Vinson/MVP said:
Hello,

Sorry. The error message says Run time error 2465 Microsoft access cant find
the field Customer_Care_Agent referred to in your expression. So I tried to
do it without the underscores and it gave me a syntax error.

It is a combobox. The control source is Customer Care Agent and the row
source is SELECT TblCCAgents.Field1 FROM TblCCAgents ORDER BY
TblCCAgents.Field1;

I'm guessing that the name of the control is (unwisely, blanks cause
problems in control and fieldnames) actually "Customer Care Agent". If
so, Access will insert the underscores in the sub name, but you need
to use square brackets in the code:

Private Sub Customer_Care_Agent_AfterUpdate()
Me![Customer Care Agent].DefaultValue = """" & Me![Customer Care
Agent] & """"
End Sub

Be sure the Me!... code is all on one line (it's word wrapping in the
newsgroup).
 

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