Combo box searching

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tranzit
    New Member
    • May 2007
    • 18

    Combo box searching

    I have a database where i am wanting a form to lookup data from one table.

    i currently have a combo box used for searching and i am wanting to have a text box display the information relating to the search

    how am i able to do this? can someone please help me?
  • JConsulting
    Recognized Expert Contributor
    • Apr 2007
    • 603

    #2
    Originally posted by tranzit
    I have a database where i am wanting a form to lookup data from one table.

    i currently have a combo box used for searching and i am wanting to have a text box display the information relating to the search

    how am i able to do this? can someone please help me?
    what field are you returning?

    in the after update event of your combo box

    me.mytextbox = dlookup("field" ,"yourtable" ,"[yourfield]=" & me.yourcombo)

    Comment

    • tranzit
      New Member
      • May 2007
      • 18

      #3
      Originally posted by JConsulting
      what field are you returning?

      in the after update event of your combo box

      me.mytextbox = dlookup("field" ,"yourtable" ,"[yourfield]=" & me.yourcombo)

      Thanks for the help. i am using a destination field as the search criteria, when the destination is selected the kilometres from the corresponding fiedld are displayed in the textbox.

      i tryed the argument you gave me but it now it tells me that there is no macro named "me".

      i am so clueless about what i need to do

      Comment

      • JConsulting
        Recognized Expert Contributor
        • Apr 2007
        • 603

        #4
        Originally posted by tranzit
        Thanks for the help. i am using a destination field as the search criteria, when the destination is selected the kilometres from the corresponding fiedld are displayed in the textbox.

        i tryed the argument you gave me but it now it tells me that there is no macro named "me".

        i am so clueless about what i need to do
        you have a form.
        your form has a combo box
        you put the lookup code I gave you in the combo box's after update event
        you put the correct names in?

        can you paste in the code you tried?

        Comment

        • tranzit
          New Member
          • May 2007
          • 18

          #5
          Originally posted by JConsulting
          you have a form.
          your form has a combo box
          you put the lookup code I gave you in the combo box's after update event
          you put the correct names in?

          can you paste in the code you tried?
          here is the code i tryed:

          me.Kms = dlookup ("kilometres"," New Plymouth","[kilometres] = " & me.Dest)

          The name of the combo box is Dest
          The name of the text box is Kms
          The name of the table is New Plymouth
          The name of the fields in the table are destination and kilometres

          Comment

          • JConsulting
            Recognized Expert Contributor
            • Apr 2007
            • 603

            #6
            Originally posted by tranzit
            here is the code i tryed:

            me.Kms = dlookup ("kilometres"," New Plymouth","[kilometres] = " & me.Dest)

            The name of the combo box is Dest
            The name of the text box is Kms
            The name of the table is New Plymouth
            The name of the fields in the table are destination and kilometres
            me.Kms = dlookup ("kilometres ","[New Plymouth]","[kilometres] = " & me.Dest)

            so you're returning kilomers by comparing kilometers to Dest?

            shouldn't it be [destination] = me.dest??

            and is it still giving you an error ? if so, what is it?

            Comment

            • tranzit
              New Member
              • May 2007
              • 18

              #7
              Originally posted by JConsulting
              me.Kms = dlookup ("kilometres ","[New Plymouth]","[kilometres] = " & me.Dest)

              so you're returning kilomers by comparing kilometers to Dest?

              shouldn't it be [destination] = me.dest??

              and is it still giving you an error ? if so, what is it?

              This is what comes up when i try the form:

              Microsoft Access can't find the macro 'me'

              the macro (or its macro group) doesn't exist, or the macro is new but hasn't been saved. note that when you enter the macrogroupname. macroname syntax in an argument, you must specify the name the macro's macro group was last saved under.

              What does that mean??????

              Comment

              • tranzit
                New Member
                • May 2007
                • 18

                #8
                Originally posted by tranzit
                This is what comes up when i try the form:

                Microsoft Access can't find the macro 'me'

                the macro (or its macro group) doesn't exist, or the macro is new but hasn't been saved. note that when you enter the macrogroupname. macroname syntax in an argument, you must specify the name the macro's macro group was last saved under.

                What does that mean??????

                Thanks for all the help i have now sorted it and it works fine

                Comment

                • JConsulting
                  Recognized Expert Contributor
                  • Apr 2007
                  • 603

                  #9
                  Originally posted by tranzit
                  Thanks for all the help i have now sorted it and it works fine
                  can you post the final solution for everyone?

                  Comment

                  • tranzit
                    New Member
                    • May 2007
                    • 18

                    #10
                    Originally posted by JConsulting
                    can you post the final solution for everyone?
                    sure,

                    in the row source of the combo box i have the following statement:
                    SELECT [Table].field, [Table].field FROM [table] ORDER BY field;

                    and in the after update of the combo box i have the following:
                    Private Sub [combo box]_AfterUpdate()
                    Me! textbox = Me! combo box.column (1)
                    End Sub

                    This allowed me to make a selection from the combo box and it displayed the corresponding data in the text box

                    Comment

                    • CindySue
                      New Member
                      • May 2007
                      • 52

                      #11
                      This seems so close to what I am trying to do, but I can't get it to work. I tried to follow the example at the end. I have a table called Regions which has two fields--County and Region. In my LP form I have a combo box called county and a text field called region. The county combo box is selecting a county from a query called "Pick List - County". I want the region field to be automatically populated with the corresponding region number as listed in the County table.

                      I have this:

                      SELECT [Pick List - County].county, [Pick List - County].county FROM [Pick List - County] ORDER BY county;

                      in my row source and it lets me pick the county. I have this:

                      Private Sub County_AfterUpd ate()
                      Me! region = Me! county.column (1)
                      End Sub

                      in the after update. It says Compile Error: Syntax Error.

                      It seems to me like I should have to reference the Regions table somehow. I played with everything I could find about dlookup, but couldn't get that to work, either. Can anyone help?

                      Comment

                      • CindySue
                        New Member
                        • May 2007
                        • 52

                        #12
                        I kept trying and finally got this to work. I put this:
                        SELECT [Regions].county, [Regions].county FROM [Regions] ORDER BY county;
                        in the row source and this:

                        Me![Region] = DLookup("[region]", "Regions", "[county] = '" & Me!County & "'")

                        as the code for after update.

                        Comment

                        Working...