textbox populated from combobox not storing value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pukhton
    New Member
    • Jun 2007
    • 75

    textbox populated from combobox not storing value

    I am having a problem with my Access database, since I am new to this, I have no idea what is goign on????

    okay here is the problem.

    I have a database which has Meds tables, and has two fields.
    1- Medication_Name
    2-Concentration

    On the form I have a combo box for Medication_Name (it has all the medication names form the Medication_Name field), and textbox for Concentration. I want my User when they pick the specific medication, the concentration textbox should get populated by itself. So, I was playing around with it, i got that part working, but the problem I am having is when the textfield for Concentration gets populated, its not saving in the main table. Is there a way we could do that?

    please help me.

    Thanks
  • AccessIdiot
    Contributor
    • Feb 2007
    • 493

    #2
    What's the control source for the textbox?

    Comment

    • pukhton
      New Member
      • Jun 2007
      • 75

      #3
      thanks for the reply. If i put the name of the field in the control source It will save in the table, but if i put this =DLookUp("Conce ntration","medq uery1") under control source I will the result, but it will not save into the table.

      its kind of complicated to explain..


      take a look of this too, it migh help you.

      Private Sub Medication_Name _Change()
      ' DoCmd.OpenQuery "medquery1"
      Me!Concentratio n.Requery
      End Sub

      and thats what i have under Query

      SELECT Meds.Concentrat ion
      FROM Meds
      WHERE (((Meds.Medicat ion_Name)=[Forms]![MainTable1]![Medication Name]));

      Comment

      • pukhton
        New Member
        • Jun 2007
        • 75

        #4
        please I need HELP regarding this..

        Comment

        • FishVal
          Recognized Expert Specialist
          • Jun 2007
          • 2656

          #5
          Originally posted by pukhton
          thanks for the reply. If i put the name of the field in the control source It will save in the table, but if i put this =DLookUp("Conce ntration","medq uery1") under control source I will the result, but it will not save into the table.

          its kind of complicated to explain..


          take a look of this too, it migh help you.

          Private Sub Medication_Name _Change()
          ' DoCmd.OpenQuery "medquery1"
          Me!Concentratio n.Requery
          End Sub

          and thats what i have under Query

          SELECT Meds.Concentrat ion
          FROM Meds
          WHERE (((Meds.Medicat ion_Name)=[Forms]![MainTable1]![Medication Name]));
          Something like this.

          [CODE=vb]

          Private Sub Medication_Name _AfterUpdate()

          Me!Concentratio n = DLookup("[Concentration]", "[Meds]", _
          "[Medication_Name] = '" & Me![Medication_Name]) & "'"

          End Sub

          [/CODE]

          Comment

          • pukhton
            New Member
            • Jun 2007
            • 75

            #6
            can u plz explain this little bit more, because i am still not getting the right answer.

            Comment

            • FishVal
              Recognized Expert Specialist
              • Jun 2007
              • 2656

              #7
              Originally posted by pukhton
              can u plz explain this little bit more, because i am still not getting the right answer.
              This sub is fired on AfterUpdate event in your combo and change the value of the text box to Concentration that matches Medical_Name in you table.

              Assumed that
              1) the type of Meds.Medical_Na me is text
              2) combo Medication_Name .BoundColumn is a column corresponding to Meds.Medical_Na me

              Take into account that DLookup function returns the first matching value only.

              Good luck.

              Comment

              • pukhton
                New Member
                • Jun 2007
                • 75

                #8
                Originally posted by FishVal
                This sub is fired on AfterUpdate event in your combo and change the value of the text box to Concentration that matches Medical_Name in you table.

                Assumed that
                1) the type of Meds.Medical_Na me is text
                2) combo Medication_Name .BoundColumn is a column corresponding to Meds.Medical_Na me

                Take into account that DLookup function returns the first matching value only.

                Good luck.

                I just copy this into the Medication_Name "after update event" but i am getting this error, i am really sorry if i am getting pain the neck

                It says Microsoft Access cant find the field 'Medication_Nam e" reffered to in your expression.
                I am sure I do have this field name Under Meds table.

                Any help please???

                Comment

                • FishVal
                  Recognized Expert Specialist
                  • Jun 2007
                  • 2656

                  #9
                  Originally posted by pukhton
                  I just copy this into the Medication_Name "after update event" but i am getting this error, i am really sorry if i am getting pain the neck

                  It says Microsoft Access cant find the field 'Medication_Nam e" reffered to in your expression.
                  I am sure I do have this field name Under Meds table.

                  Any help please???
                  I can suggest you the following another way.

                  1) change in design view the following Medication_Name combo properties
                  .RowSource="SEL ECT Meds.Concentrat ion, Meds.Medication _Name FROM Meds; "
                  .BoundColumn=2
                  .ColumnCount=2
                  .ColumnWidths=0 ;10

                  2) write another AfterUpdate event handler

                  [CODE=vb]
                  Private Sub Medication_Name _AfterUpdate()

                  With Me.Medication_N ame
                  Me.Concentratio n = .Column(0, .ListIndex)
                  End With

                  End Sub
                  [/CODE]

                  I've checked this. It works fine.

                  Good Luck.

                  PS. If your combo is not bound to table, the code will be even more simple.

                  Comment

                  • pukhton
                    New Member
                    • Jun 2007
                    • 75

                    #10
                    Originally posted by FishVal
                    I can suggest you the following another way.

                    1) change in design view the following Medication_Name combo properties
                    .RowSource="SEL ECT Meds.Concentrat ion, Meds.Medication _Name FROM Meds; "
                    .BoundColumn=2
                    .ColumnCount=2
                    .ColumnWidths=0 ;10

                    2) write another AfterUpdate event handler

                    [CODE=vb]
                    Private Sub Medication_Name _AfterUpdate()

                    With Me.Medication_N ame
                    Me.Concentratio n = .Column(0, .ListIndex)
                    End With

                    End Sub
                    [/CODE]

                    I've checked this. It works fine.

                    Good Luck.

                    PS. If your combo is not bound to table, the code will be even more simple.
                    sorry I tried that, but still nothing...i am sure its me. I am not sure how to fix this crap. I will appreciate it if i can send yout the file on your email id, take a look, and see what am i doing wrong?

                    thanks
                    let me know plz.

                    Comment

                    • FishVal
                      Recognized Expert Specialist
                      • Jun 2007
                      • 2656

                      #11
                      Originally posted by pukhton
                      sorry I tried that, but still nothing...i am sure its me. I am not sure how to fix this crap. I will appreciate it if i can send yout the file on your email id, take a look, and see what am i doing wrong?

                      thanks
                      let me know plz.
                      Sure.
                      By the way it will be interesting for me to see myself what a is happening in your db.

                      Comment

                      • FishVal
                        Recognized Expert Specialist
                        • Jun 2007
                        • 2656

                        #12
                        Originally posted by FishVal
                        Sure.
                        By the way it will be interesting for me to see myself what a is happening in your db.
                        Sorry the option to receive e-mails was disabled. Now you can sent. If you will enable this option in your profile I will send you my sample.

                        Comment

                        • pukhton
                          New Member
                          • Jun 2007
                          • 75

                          #13
                          Originally posted by FishVal
                          Sorry the option to receive e-mails was disabled. Now you can sent. If you will enable this option in your profile I will send you my sample.
                          Thanks, and sorry for taking long. I have enabled my email, so please send me yours. I am sending you mine. Take a look.

                          You will see on the main form u have a Medication combo box and right under that you have a concentration text box. I want my user to pick medication from the drop down menu, when they do that, the text box for concentration should get populated by it self from the table "Meds". Each medication has a standrad concentration. It works fine on the form, but the concentration text box is not saving into the MainTable. Please take a look, and help me out.

                          Comment

                          • pukhton
                            New Member
                            • Jun 2007
                            • 75

                            #14
                            Originally posted by pukhton
                            Thanks, and sorry for taking long. I have enabled my email, so please send me yours. I am sending you mine. Take a look.

                            You will see on the main form u have a Medication combo box and right under that you have a concentration text box. I want my user to pick medication from the drop down menu, when they do that, the text box for concentration should get populated by it self from the table "Meds". Each medication has a standrad concentration. It works fine on the form, but the concentration text box is not saving into the MainTable. Please take a look, and help me out.
                            sorry it doesnt let me attach the file, syas invalid file. I thinks its mdb file thats why..
                            please send me your file at pukhton77@hotma il.com
                            and i will send you mine back.

                            Comment

                            • pukhton
                              New Member
                              • Jun 2007
                              • 75

                              #15
                              I need help please.

                              What i am trying to achieve is to save value from Meds Table and save it in Main Table.

                              Meds tabel has two colums, Medication_Name and Concentration.
                              Each medication has standrad concentration.

                              I have a combo box for Medications and text box for Concentration in my Form. When User picks medication, the concentration text box gets populated from the Meds colum, but that value is not saving in the Main Table.
                              please help me out...

                              Comment

                              Working...