Results 1 to 8 of 8
  1. #1
    dfelock is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Posts
    11

    Most likely a programming thing


    So I'm trying to make a spot on my form that when a person selects a number from a drop down list, the number is then brought down to another part of the form and the number's description is displayed next to it. Any ideas?

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    take a look at this small one-liner for an example of how you might do it...

  3. #3
    dfelock is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Posts
    11
    Quote Originally Posted by ajetrumpet View Post
    take a look at this small one-liner for an example of how you might do it...
    I should just be able to copy the code correct? and change the names of the tables and such?

    So I tried copying and just putting the names of my tables and stuff to fit where needed, but it didn't work. How can I compress the file to share so people can tell me how much I've screwed up?
    Last edited by dfelock; 12-17-2010 at 07:19 PM. Reason: New question

  4. #4
    dfelock is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Posts
    11
    Trying to see if this attachment works...

    This is what I currently have with the line of code you provided me Adam, with my stuff thrown in, but something isn't working....

  5. #5
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    hey bud,

    your source of the dropdown is:
    Code:
    SELECT [Offenses].[ID], Offenses.[Offense] FROM Offenses;
    and the code is right.

    the reason it doesn't work is because the code is reading the first column. you have two, because the source queries two fields. that trips everyone up the first time, I'm sure.

    you can fix it two ways. change the source to:
    Code:
    SELECT Offenses.[Offense] FROM Offenses;
    OR change the code to:
    Code:
    Me.Text1 = Application.DLookup("OffenseDesc", "Offenses", "[Offense] = '" & Me.Combo13.Column(1, 0) & "'")

  6. #6
    dfelock is offline Novice
    Windows Vista Access 2007
    Join Date
    Dec 2010
    Posts
    11
    Quote Originally Posted by ajetrumpet View Post
    hey bud,

    your source of the dropdown is:
    Code:
    SELECT [Offenses].[ID], Offenses.[Offense] FROM Offenses;
    and the code is right.

    the reason it doesn't work is because the code is reading the first column. you have two, because the source queries two fields. that trips everyone up the first time, I'm sure.

    you can fix it two ways. change the source to:
    Code:
    SELECT Offenses.[Offense] FROM Offenses;
    OR change the code to:
    Code:
    Me.Text1 = Application.DLookup("OffenseDesc", "Offenses", "[Offense] = '" & Me.Combo13.Column(1, 0) & "'")
    Okay, so I used the second code and it works, to a point. It only enters the first OffenseDesc each time no matter what Offense I pick.
    Last edited by dfelock; 12-17-2010 at 10:28 PM. Reason: new issue

  7. #7
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by dfelock View Post
    Okay, so I used the second code and it works, to a point. It only enters the first OffenseDesc each time no matter what Offense I pick.
    I'm sorry sir. Friday night I guess. this:
    Code:
    Me.Text1 = Application.DLookup("OffenseDesc", "Offenses", "[Offense] = '" & Me.Combo13.Column(1, 0) & "'")
    was untested by me. My mistake. You need to reduce the query to one field. if you drop the id field completely, your initial code will be fine.

    My apologies once again.

  8. #8
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Okay, so I used the second code and it works, to a point. It only enters the first OffenseDesc each time no matter what Offense I pick.
    By using the optional row argument of the column property of the combo box (the 0 >> Me.Combo13.Column(1, 0)), you are telling the result to always come from the first row (zero based).

    You should use:

    Code:
    Me.Combo13
    or 
    Me.Combo13.Column(0)
    The default value is the bound column, which is column 0 (the first column).


    If you set the row source of the combo box to

    Code:
    SELECT [Offenses].[ID], Offenses.[Offense] FROM Offenses;
    then the control source for text box "Text1" would be

    Code:
    Me.Text1 = Me.Combo13 & ", " & Me.Combo13.Column(1) 
    or
    Me.Text1 = Me.Combo13.Column(0) & ", " & Me.Combo13.Column(1)
    first column (column zero) concatenated to the second column (column one)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Is my programming wrong? :(
    By radicrains in forum Programming
    Replies: 5
    Last Post: 10-27-2010, 08:39 PM
  2. Craziest Thing You've Seen/Done
    By Rawb in forum Access
    Replies: 1
    Last Post: 10-25-2010, 02:56 PM
  3. 2 programming issues
    By gripper in forum Programming
    Replies: 3
    Last Post: 10-06-2010, 11:10 AM
  4. Help Please - Programming Labels
    By graviz in forum Programming
    Replies: 4
    Last Post: 03-02-2010, 10:37 PM
  5. VB Programming
    By mstefansen in forum Programming
    Replies: 4
    Last Post: 08-31-2009, 07:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums