Unanswered: Using VB code to add new record to table
Hello. I have a small problem. I've tried searching the VB and Access forums and have found similar questions but I just need a little bit of extra information.
I have an access database with a combo box (cbo_Book) on a form. The combo box gets its contents from the table (tbl_Book).
I have it set up so that the user can select a name from cbo_Book and either edit (cmd_Edit) or view (cmd_View) the table relating to the book.
Now, I have added an extra cmd (cmd_Add) so the user can add a new Book and view and/or edit their new book table. (I have done this using CopyObject to make a copy of a TemplateTable). The only problem is that I can't get the new book name to go to tbl_Book so that it appears in the combo box. Ie - Once they write the new book name in the combo, they can view or edit the table, but if they change to a different book in the combo box, their entry is not in the combo, but the table still exists.
If anyone can give me some simple VB code to make the users entry go to tbl_book and be displayed in the combo box without having to close the whole thing down, that would be greatly appreciated.
I dont know where this "Me" stuff comes from. I assume SQL. I'm using VB to code everything. Do I need to requery the combo box or the table? Because I want the input entered by the user to remain in the combo box when another value is selected.
"Me" is a VBA word used as a shortcut to reference the current object (see Help for a full explanation).
I am assuming that your problem is that a new book is added to the books table, but does not appear on the combo box. If that is the case then you need to requery the combo box to update its list of books. You use the command:
Me("My Combo Box Name").Requery
If your problem is that the new book is not appearing in the books table then you need to use the NotInList event and LimitToList property of the combo box - see Access Help for guidance on how to use these.