[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.
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.
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
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.
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
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
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
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.