Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding data to a table W / 1 field that acts a list box.

Status
Not open for further replies.

Tofias1

MIS
Jun 17, 2002
57
US
Hello to anyone who takes a look at my problem. Thanks in advance.
Well, here is my problem. I have a table that stores names. It is connected to other forms as a list box to choose the names from. What I would like to do is have a input box open up once a cmd button is clicked. The user will then enter a name within the box and it will post into the table once OK is clicked, allowing the user to select it from a list. Here is my code but nothing happens except for the input. I have no idea where the data is going. (Names is the table and because this is a testing mdb the field is also named Names) I am pretty sure it would work with a few chages in VB but I can not figure it out in VBA.

Private Sub Add_Data_Click()
Dim Varanswer As String
Dim rst As DAO.Recordset
Dim One As String

Varanswer = InputBox("Please Enter the Name which you would like to add.")
If Varanswer = "1" Then

Set rst = CurrentDb.OpenRecordset(Names, dbOpenDynaset)

One = Varanswer
With rst
.AddNew
!Names = Me!Names.Column(0, One)
.update

End With

End If

End Sub


Any help would be greatly appreciated.
Tofias1

 
1. Careful using Names as a name in a DB...I'd be chicken to do it.

2. Make a form that adds names to the Names table.

3. As the on-click for your command button, just open the "Add Name" form.

4. Do an on-close of the "Add Name" form to refresh your original form.

?
I don't do code really, but I know I've done/seen something similar to this. Anne Troy
Dreamboat@TheWordExpert.com
Anne@MrExcel.com
 
Anne,

Originally I was thinking of doing it that way. I wanted to get away from opening a form and using code instead, however, I will try doing it this way it sounds a lot easier. Thanks for your reply.

Tofias1
 
You still need the form to add the data. And you'll be using code to launch the form.

:) Anne Troy
Dreamboat@TheWordExpert.com
Anne@MrExcel.com
 
That makes sense. Well I will give it a shot and let you know how it came out.

Tofias1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top