Add entry to drop down list

G

Guest

I need to find out how to allow a user to add an item to a drop down list
that does not already exist in the drop down list. I am not sure If i need
to write a macro to do this or if there is a setting that can be used.

For instance. A user is entering data in the database. The come to a field
in the form that has a drop down list of categories including "staff",
"trainees", and "agencies". The information they are entering needs to to go
into the category "vendors". I have the field set to No for limit to list,
but how do I get the data they enter to automatically add to the list?

Thanks.
 
G

Guest

Hi Risikio -- Below is a sub from one of my DBs that adds an item to the
list. You can substitute you fields, table, etc.

Private Sub cboPaidTo_NotInList(NewData As String, Response As Integer)

Dim db As DAO.Database
Dim YesNo As VbMsgBoxStyle

YesNo = Msgbox("Enter New Value?", vbYesNo + vbQuestion +
vbDefaultButton1, "NEW VALUE")

Select Case YesNo
Case vbYes
Set db = CurrentDb()

DoCmd.OpenForm "frmEditExpenses", acNormal, , , acFormAdd, acDialog

'Add the new value to the field
' db.Execute "INSERT INTO tblPaidToRef (EntityName) " & _
' "VALUES (""" & NewData & """)", dbFailOnError

'Tell Access you've added the value
Response = acDataErrAdded

db.Close
Set db = Nothing

Case vbNo
cboPaidTo.Text = ""
End Select

End Sub
 
G

Guest

I think I found the answer. I had to go into the form to set a On Not in
List [Event Procedure]. I was looking for it in the tables. Does the [Event
Procedure] automatically write the correct code? I am not real good with the
visual basic side of access.
 
G

Guest

Thanks. I will give this a try.

xRoachx said:
Hi Risikio -- Below is a sub from one of my DBs that adds an item to the
list. You can substitute you fields, table, etc.

Private Sub cboPaidTo_NotInList(NewData As String, Response As Integer)

Dim db As DAO.Database
Dim YesNo As VbMsgBoxStyle

YesNo = Msgbox("Enter New Value?", vbYesNo + vbQuestion +
vbDefaultButton1, "NEW VALUE")

Select Case YesNo
Case vbYes
Set db = CurrentDb()

DoCmd.OpenForm "frmEditExpenses", acNormal, , , acFormAdd, acDialog

'Add the new value to the field
' db.Execute "INSERT INTO tblPaidToRef (EntityName) " & _
' "VALUES (""" & NewData & """)", dbFailOnError

'Tell Access you've added the value
Response = acDataErrAdded

db.Close
Set db = Nothing

Case vbNo
cboPaidTo.Text = ""
End Select

End Sub
 
G

Guest

No, you'll need to write the code, which you have in my sub. The
only thing you have to do is substitute the appropriate names. Also, make
sure the SQL execute statement isn't commented out.

Risikio said:
I think I found the answer. I had to go into the form to set a On Not in
List [Event Procedure]. I was looking for it in the tables. Does the [Event
Procedure] automatically write the correct code? I am not real good with the
visual basic side of access.

Risikio said:
I need to find out how to allow a user to add an item to a drop down list
that does not already exist in the drop down list. I am not sure If i need
to write a macro to do this or if there is a setting that can be used.

For instance. A user is entering data in the database. The come to a field
in the form that has a drop down list of categories including "staff",
"trainees", and "agencies". The information they are entering needs to to go
into the category "vendors". I have the field set to No for limit to list,
but how do I get the data they enter to automatically add to the list?

Thanks.
 
G

Guest

Thanks again. I had posted my finding at the same time your posted your
code. I am working on it now.

Thank you again.

xRoachx said:
No, you'll need to write the code, which you have in my sub. The
only thing you have to do is substitute the appropriate names. Also, make
sure the SQL execute statement isn't commented out.

Risikio said:
I think I found the answer. I had to go into the form to set a On Not in
List [Event Procedure]. I was looking for it in the tables. Does the [Event
Procedure] automatically write the correct code? I am not real good with the
visual basic side of access.

Risikio said:
I need to find out how to allow a user to add an item to a drop down list
that does not already exist in the drop down list. I am not sure If i need
to write a macro to do this or if there is a setting that can be used.

For instance. A user is entering data in the database. The come to a field
in the form that has a drop down list of categories including "staff",
"trainees", and "agencies". The information they are entering needs to to go
into the category "vendors". I have the field set to No for limit to list,
but how do I get the data they enter to automatically add to the list?

Thanks.
 
G

Guest

Great, let me know if you run into any problems by posting your own code.
Good Luck.

Risikio said:
Thanks again. I had posted my finding at the same time your posted your
code. I am working on it now.

Thank you.

xRoachx said:
No, you'll need to write the code, which you have in my sub. The
only thing you have to do is substitute the appropriate names. Also, make
sure the SQL execute statement isn't commented out.

Risikio said:
I think I found the answer. I had to go into the form to set a On Not in
List [Event Procedure]. I was looking for it in the tables. Does the [Event
Procedure] automatically write the correct code? I am not real good with the
visual basic side of access.

:

I need to find out how to allow a user to add an item to a drop down list
that does not already exist in the drop down list. I am not sure If i need
to write a macro to do this or if there is a setting that can be used.

For instance. A user is entering data in the database. The come to a field
in the form that has a drop down list of categories including "staff",
"trainees", and "agencies". The information they are entering needs to to go
into the category "vendors". I have the field set to No for limit to list,
but how do I get the data they enter to automatically add to the list?

Thanks.
 

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