Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2003
    Location
    Londo, UK
    Posts
    20

    Unanswered: populating text box from combobox

    I have tried looking for the answer to my problem to no avail.

    I have three tables, tblName, tblBook, tblOrder, and a query which links the three to give the book that the person ordered, with the price and frequency of publication.
    I am trying to create a form to enable the user to enter and change data.
    I have text boxes for surname, fname, tel no, price and frequency bound to the qryOrder. I have a combobox bound to the tblBook, which selects the book, price and frequency, the columns set to three, with widths of 2.45cm,0,0.

    When a user changes the choice of book in the combo box, I need the text boxes price and frequency to change in line with the tblBook and to update the data in the underlying qryOrder.

    I have tried on the AfterUpdate() event:
    Private Sub Combo32_AfterUpdate()
    me.price=me.combo32.column(2)
    End Sub

    This gives an error message "Module not found" and then it locks the database and I have to close it and re-open it.

    I am not very good at coding, or understanding all the options in the properties.

    Any help you can give me will be greatly appreciated.
    Janet

  2. #2
    Join Date
    Oct 2009
    Posts
    340
    Private Sub Combo32_AfterUpdate()
    me.price=me.combo32.column(2)
    End Sub

    gives an error message "Module not found" and then it locks the database ???

    ooh that is not good.... first I would delete that combobox totally and make a new one just to be safe. that code that you have should work...

    your Price text box - if it is unbound could just have the source control be:
    =me.comboboxname.column(2)

    and you won't need any AfterUpdate code - - though that code is so simple that you have it shouldn't be throwing any error ....

    if your Price text box is bound - then you'll have to retry your AfterUpdate code...

  3. #3
    Join Date
    Aug 2003
    Location
    Londo, UK
    Posts
    20
    I deleted the combobox and tried again with the same code. I am still getting the "Module not found" error message. The info about this says the following which I find totally incomprehensible. What do they mean by module?

    "Modules aren't loaded from a code reference they must be part of the project. This error has the following cause and solution:

    The requested module doesn't exist in the specified project. For example, the statement MyModule.SomeVar = 5 generates this error when MyModule isn't visible in the project MyProject.
    See your host application documentation for information on including the module in the project."

    Another error message now comes up:
    "The form name 'Data Entry' is misspelt or refers to a form that doesn't exist" . Repeated attempts to close this by clicking the OK button is needed but that then closes the whole database.

    The combobox works OK in changing the data in the query for the book without the AfterUpdate code. At least it did but now it has stopped doing even that.

    The Price textbox is bound, its ControlSource is the price field from the qryBook.

    The only other thing which I have done in order to get the original combobox to work (Before trying to populate text boxes). was to change the form's RecordSetType to Dynaset(InconsistenUpdates) which I picked up from a thread somewhere. After this I was able to change the data in the book field. Previously I would just get a peep and nothing happened.

    It's getting worse. Now when \I go from record to record it says the "The Value you entered isn't valid for this field"
    AND when I try to change the book in the combobox it is storing the BookId in the queryBook.



    I seem to be, no I am, going backwards. I'm a lot worse than when I started.

    Where am I going wrong? I think I shlal have to start a new form totally as this one seems to be such a mess now.
    Janet

  4. #4
    Join Date
    Aug 2003
    Location
    Londo, UK
    Posts
    20
    Right. I have now created a completely new form, based on the qryBook with a combobox based on the tbl.book.
    The combobox initially put the bookid in the query, (it was bound to column one - the rowsource is
    SELECT tblBook.BookID, tblBook.Book, tblBook.Price, tblBook.Frequency
    FROM tblBook
    ORDER BY tblBook.Book. When I changed the Bound Column to 2, it then entered the name of the book.

    Then I added the code me.Price=me.Combobox24.column(3) to the AfterUpdate event (I put column 3 because of the earlier problem mentioned above - I thought if the book title was column 2, then the price should be column3)
    Then tried to run it and I again got the "Module not found" error message. Trying to clear this then brought up the error about the Data Entry form being misspelt. This took several clicks on the OK button to clear and it then closed the database completely.
    I think I will attach the database so that you can perhaps spot what I am missing.
    The original form is frmData, the new form is frmEnterInfo - I have not done any rearrangements, or layout on this yet.
    I hope this works OK.

    Many thanks for any help you can give me, I am getting even more grey hairs than I had at the beginning of the week.
    Attached Files Attached Files
    Janet

  5. #5
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    You have a couple of things going. The first is the database wouldn't compile or compact/repair due to a missing (corrupt) form called Data Entry - ie. Tools -> Database Utilities -> Compact/Repair. This form doesn't exist but your mdb thinks it does.

    The 2nd is that your combobox name isn't correct in your code and is using the wrong column to grab the value.

    I imported all the objects into a brand NEW mdb file and corrected the combobox. (Note: if you get an error when compacting/compiling that a form doesn't exist or module not found, this is often a sign of a corrupt mdb.)

    See attached for a fixed version that works.

    Remember to always debug/compile and compact/repair your mdb as your developing it (I do this often - ie. after any code changes.)
    Attached Files Attached Files
    Last edited by pkstormy; 01-16-10 at 12:00.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  6. #6
    Join Date
    Aug 2003
    Location
    Londo, UK
    Posts
    20
    Many, many thanks. I really appreciate your help.

    Thanks for the tip about debug/compile and compact/repair, I had not thought of doing that.

    It works fine now. I have put the code to update the frequency field in as well and that works too.
    Janet

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •