Results 1 to 15 of 15

Thread: [RESOLVED] Check Command Button status in database at the time of execute...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2012
    Posts
    90

    Resolved [RESOLVED] Check Command Button status in database at the time of execute...

    Hi all,

    I have 3 command buttons in my form. when I execute program, I need to check my database/Table for some query.
    below is my code...

    Code:
    private function ChkData()
    set rs = db.opentable("Select * from abc where isdel = false")
    if rs!TNo = "T 1" then cmd1.backcolor = vbred else cmd1.backcolor = vbgreen
    if rs!TNo = "T 2" then cmd2.backcolor = vbred else cmd2.backcolor = vbgreen
    if rs!TNo = "T 3" then cmd3.backcolor = vbred else cmd3.backcolor = vbgreen
    end function
    Code:
    private sub Form_Load()
    chkdata
    end sub
    I tried with do while...loop also but I didn't get what I want.

    so, plz help for same.

    Thanks in advance

    kaushal

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Check Command Button status in database at the time of execute...

    I don't understand your question.

    What query are you checking for and what do the command buttons have to do with it?

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Check Command Button status in database at the time of execute...

    He's setting button's backcolor based on what's in the table...

    1. You don't have to select all fields if you only need one of them - you can use "Select TNo from ..." instead. (if records are not unique add Distinct)
    2. How many records do you expect that query to return - check your database directly.
    3. Suppose your query returns 3 records DID you set button's Style to Graphical?
    4. And Yes, you need to loop through your recordset.

    ...some other questions may follow...

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Check Command Button status in database at the time of execute...

    You should also not be using the OpenTable method

    You should be using ADO with a forward only recordset and you should close the recordset when you are done.

    As for looping ... not sure what you are trying to do, how many records, do you really want to cycle through all of them?

    Note that if you had say 100 records and 1 or more of those records had a value of 1, 1 or more had a value of 2, and one or more had a value of 3 then all three buttons would have the color changed but you would have no idea what record changed which button nor how many records were set to any of those numbers only that there is at least 1.

    Perhaps you should explain what you are trying to do in a bit more detail

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2012
    Posts
    90

    Re: Check Command Button status in database at the time of execute...

    hi All,

    Thanks for your reply...

    I am doing software for a restaurant. those 3 command buttons are for TABLEs (in a restaurant). When i press Cmd1 it means it will create new KOT and its color will change to RED. now, whenever that KOT finish means Invoice generate for that KOT then and then Cmd1 become GREEN.

    now, meanwhile due to any problem computer system shutdown. now when i restart my system and a software i want Command Buttons in RED if those KOT are not FINISHED or CLEAR.

    hope, i explained my idea clearly. I tried "Do While...Loop" also but not fruitful.

    so, plz help.

    thanks.

    Kaushal

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Check Command Button status in database at the time of execute...

    How many records are in your database? Are there only 3 tables in the restaurant? 3 records in the table?

    Need more info

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 2012
    Posts
    90

    Re: Check Command Button status in database at the time of execute...

    there are numbers of records in database. no, there are more then 3 tables in the restaurant.

    there is a field called TblDel in KOTMstr (Table). whenever a invoice generated for a particular table, at that time TblDel = True for same KOT.

    here I attached a screenshot of my form for your reference.
    Attached Images Attached Images  

  8. #8
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Check Command Button status in database at the time of execute...

    Are you changing the colour of the table buttons or the "Execute" button? How do you check if a KOT is finished or not?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  9. #9
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Check Command Button status in database at the time of execute...

    Still do not know how many records are in the database and have asked twice already. The thing is that if there are more records than tables you must use a different approach.
    Hard to give good advice without good info

    you could for starters do this and see what happens
    Code:
    private function ChkData()
    cmd1.backcolor = vbgreen
    cmd2.backcolor = vbgreen
    cmd3.backcolor = vbgreen
    set rs = db.opentable("Select * from abc where isdel = false")
    Do While Not rs.eof
    if rs!TNo = "T 1" then 
         cmd1.backcolor = vbred 
    else if rs!TNo = "T 2" then 
         cmd2.backcolor = vbred 
    else if rs!TNo = "T 3" then 
         cmd3.backcolor = vbred 
    End If
    rs.movenext
    loop
    
    end function

  10. #10
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Check Command Button status in database at the time of execute...

    Another thing: I would replace the single command-buttons with a control-array, where depending on the Value "T x" from the database (providing he solves his initial problem) he can directly assign the backcolor using the Index of the command-button.
    Code should look much cleaner that way
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  11. #11
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Check Command Button status in database at the time of execute...

    Agreed I also would use a control array

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jul 2012
    Posts
    90

    Re: Check Command Button status in database at the time of execute...

    BINGO....!

    Thanks a lot, DataMiser.

    thanks everyone.

    kaushal

  13. #13
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Re: Check Command Button status in database at the time of execute...

    I tried with do while...loop also but I didn't get what I want.

    so, plz help for same.

    Thanks in advance
    you can use do ... until .... loop also . please always consider to use err handler .
    Code:
    private function ChkData()
    on error goto errhnd
    cmd1.backcolor = vbgreen
    cmd2.backcolor = vbgreen
    cmd3.backcolor = vbgreen
    set rs = db.opentable("Select * from abc where isdel = false")
    Do until  rs.eof
    if rs!TNo = "T 1" then 
         cmd1.backcolor = vbred 
    else if rs!TNo = "T 2" then 
         cmd2.backcolor = vbred 
    else if rs!TNo = "T 3" then 
         cmd3.backcolor = vbred 
    End If
    rs.movenext
    loop
    exit function
    errhnd:
    msgbox(err.number  & ":" & err.description)
    end function
    Last edited by firoz.raj; Sep 20th, 2013 at 02:10 PM.

  14. #14
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: [RESOLVED] Check Command Button status in database at the time of execute...

    Actually
    Code:
    Do until Not rs.eof
    Would not work at all

    Either eof would be true and it would throw an error or eof would be false and the loop would not execute at all.

    the proper line would be
    Code:
    Do until rs.eof

  15. #15
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Smile Re: [RESOLVED] Check Command Button status in database at the time of execute...

    Either eof would be true and it would throw an error or eof would be false and the loop would not execute at all.

    the proper line would be
    Code:
    Do until rs.eof
    really i did not notice .

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