Results 1 to 13 of 13

Thread: Details shown always first

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2019
    Posts
    16

    Details shown always first

    Hi Sirs,

    I would like to ask what is my error in this code? i am trying to display the details of the total quantity of Labeler and Ballpen whenever selected from the combo box. But if i chose the labeler it will show the total quantity of Ballpen always. since it is the first detail in the access database

    Code:
    Private Sub cmbItem_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbItem.SelectedIndexChanged
      Sup.Open("Select*from Supply", database)
         
    
            If cmbItem.Text = "Labeler" Then
                txtCurrent.Text = Sup.Fields("Supply_Quantity").Value
                 txtItemCode.Text = Sup.Fields("Item_Number").Value
            End If
    
            If cmbItem.Text = "Ballpen" Then
                txtCurrent.Text = Sup.Fields("Supply_Quantity").Value
                txtItemCode.Text = Sup.Fields("Item_Number").Value
            End If
    Thanks guys for your future inputs. sorry super beginner
    Last edited by Shaggy Hiker; Mar 19th, 2021 at 09:52 AM. Reason: Added CODE tags.

  2. #2
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    2,068

    Re: Details shown always first

    Hi BeginnerMe,

    First error, nothing to do with your question... Subroutine and Function names should always start with an upper case letter, I'm surprised that Intellisence hasn't complained.

    Next, Ok, so you're new in here too, when you show code please use the tool provided...
    In the heading when you're typing in your question there is a button with a hash symbol, '#'. Just before you enter any code, click that button, it will place a pair of [controls] on the page, at the caret. Place (paste) your code between the two.
    Code:
    Private Sub cmbItem_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbItem.SelectedIndexChanged
    Sup.Open("Select*from Supply", database)
    
    
    If cmbItem.Text = "Labeler" Then
    txtCurrent.Text = Sup.Fields("Supply_Quantity").Value
    txtItemCode.Text = Sup.Fields("Item_Number").Value
    End If
    
    If cmbItem.Text = "Ballpen" Then
    txtCurrent.Text = Sup.Fields("Supply_Quantity").Value
    txtItemCode.Text = Sup.Fields("Item_Number").Value
    End If
    Ok, your problem,
    When it comes to comparing texts, the two texts have to be exactly the same to get a true result.
    e.g. 'Ballpen' does not equal 'ballpen'. This is probably not your problem but keep it in mind.

    The fact that the selected item has changed has called the subroutine, but your code doesn't identify which index it has changed to.
    Put a BreakPoint at the line 'If cmbItem.Text = "Labeler"', run the code, then when it breaks, take a look at the value of 'sender'. This ought to help.


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    36,154

    Re: Details shown always first

    Quote Originally Posted by Poppa Mintin View Post
    Hi BeginnerMe,

    First error, nothing to do with your question... Subroutine and Function names should always start with an upper case letter, I'm surprised that Intellisence hasn't complained.
    That's not a rule, it's just a convention. Whether or not anything complains depends on what settings you have. Style checkers would complain, but base VS shouldn't.


    As to the question, I don't know what Sup is...though I hesitate to ask, "What Sup?"

    Still, there is clearly a query being done in there, since you have this SQL "Select*from Supply" statement. But that doesn't have a WHERE clause, so it ALWAYS returns everything. It returns everything when you select one thing, it returns everything when you select a different thing, and everything is just everything, which means that those If statements do nothing. Whatever is in Sup is the same no matter what selection is made in the combobox, since the SQL is the same in all cases. You need to have Sup hold something different depending on the selection in the combobox, which probably means that you need to have different SQL in that first line depending on the selection in the combobox.
    My usual boring signature: Nothing

  4. #4
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    2,068

    Re: Details shown always first

    Quote Originally Posted by Shaggy Hiker View Post
    First error, nothing to do with your question... Subroutine and Function names should always start with an upper case letter, I'm surprised that Intellisence hasn't complained.
    That's not a rule, it's just a convention. Whether or not anything complains depends on what settings you have. Style checkers would complain, but base VS shouldn't.
    I haven't started a Subroutine or Function name with a lower case letter since Intellisence complained in about VS2005.
    Maybe it's changed ?

    Poppa
    Along with the sunshine there has to be a little rain sometime.

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    36,154

    Re: Details shown always first

    I never do, and I don't remember 2005. Still, I don't believe there is a rule enforced by the compiler. There has long been a Code Analysis tool to check your code, which had LOADS of nitpicky little rules like that. Perhaps that wasn't a separate tool back then, or perhaps you ran Code Analysis and are remembering that. I found that I had to turn off LOTS of the messages Code Analysis would give me. I felt they were reasonable, in some cases, and not in others. One of the ones that amused me was that it would object if I didn't initialize local variables, but VS would object if I did.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Mar 2019
    Posts
    16

    Re: Details shown always first

    Hi Guys, sorry. Sup is for recordset...

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    36,154

    Re: Details shown always first

    Yeah, fine, but it's always the SAME recordset, regardless of what the combobox is. You need it to be a different recordset depending on the value in the combobox. Your SELECT statement has to have a WHERE clause on it that returns different records for different combobox settings. Alternatively, if you were using a datatable, you could filter that rather than changing the SELECT statement, but for a recordset, I think your only choice is to change that SELECT statement.
    My usual boring signature: Nothing

  8. #8
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    2,068

    Re: Details shown always first

    Hi,

    Are you trying what is suggested?
    Have you understood what Shaggy Hiker is telling you?
    Have you looked at the value of 'sender' at the first code line of your subroutine?


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  9. #9
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    2,068

    Re: Details shown always first

    Quote Originally Posted by Shaggy Hiker View Post
    That's not a rule, it's just a convention. Whether or not anything complains depends on what settings you have. Style checkers would complain, but base VS shouldn't.
    I've just started a subroutine and missed the shift key for the first character:
    Code:
        Private Sub check()
    
        End Sub
    I immediately got this in the 'Error List'...
    Naming rule violation: These words must begin with upper case characters: check
    ...Ok, so it's not an error, just a warning, but it's what I remember from way back.


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,976

    Re: Details shown always first

    As far as Iíve seen, Shaggy has answered your question.., your SQL query was wrong. Those if statements do nothing. Both contain the same code...

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    36,154

    Re: Details shown always first

    Quote Originally Posted by Poppa Mintin View Post
    I've just started a subroutine and missed the shift key for the first character:
    Code:
        Private Sub check()
    
        End Sub
    I immediately got this in the 'Error List'...
    ...Ok, so it's not an error, just a warning, but it's what I remember from way back.


    Poppa
    We've already established that your installation comes up with some interesting warnings that nobody else seems to get. This looks like another example of that. It's pretty interesting that you are getting things like this, and that one about the unused variable.
    My usual boring signature: Nothing

  12. #12
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Skunthorpe, North Lincolnshire, England.
    Posts
    2,068

    Re: Details shown always first

    Yeah,

    I only mentioned this because we were discussing this particular subject recently in this thread.

    Pop
    Along with the sunshine there has to be a little rain sometime.

  13. #13
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,799

    Re: Details shown always first

    Quote Originally Posted by BeginnerMe View Post
    Hi Sirs,

    I would like to ask what is my error in this code? i am trying to display the details of the total quantity of Labeler and Ballpen whenever selected from the combo box. But if i chose the labeler it will show the total quantity of Ballpen always. since it is the first detail in the access database

    Code:
    Private Sub cmbItem_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbItem.SelectedIndexChanged
      Sup.Open("Select*from Supply", database)
         
    
            If cmbItem.Text = "Labeler" Then
                txtCurrent.Text = Sup.Fields("Supply_Quantity").Value
                 txtItemCode.Text = Sup.Fields("Item_Number").Value
            End If
    
            If cmbItem.Text = "Ballpen" Then
                txtCurrent.Text = Sup.Fields("Supply_Quantity").Value
                txtItemCode.Text = Sup.Fields("Item_Number").Value
            End If
    Thanks guys for your future inputs. sorry super beginner
    this look's like a mix of VB6 Code with .Net
    Code:
    'VB6 Code 
     txtCurrent.Text = Sup.Fields("Supply_Quantity").Value
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

Posting Permissions

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



Click Here to Expand Forum to Full Width