Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with code - again

Status
Not open for further replies.

kfenner

Technical User
Apr 6, 2003
52
US
I need some assistance, again.......I want to try to use the following code, found in an article from this site, to cause a button to open a report based on the current open record. Problem is, in order to successfully key this table, I have to key two fields. How do I alter the code:

var
roi ReportOpenInfo ; parameters for the report.
rpt Report ; the report itself
tc tCursor ; used to capture the current record
endVar

tc.attach( keyField )
tc.setRange( KeyField.Value, KeyField.Value );
tc.instantiateView( ":pRIV:ANSWER" )

roi.Name = "MYREPORT"
roi.MasterTable = ":pRIV:ANSWER"

rpt.open( roi )

I could try to use an arbitrary field for the key, in order to just have one keyed field, but I have no clue how to go about this successfully.

Any help is, as always, greatly appreciated.
 
kefenner,

This shouldn't be a problem, key the table on two fields and change the setRange() to use 3 arguments

tc.setRange(firstKeyValue, secondKeyValue, secondKeyValue)

for example if the table's primary key was "firstName" and the secondary key was "lastName" set the range to

tc.setRange(firstname.value, lastname.value, lastname.value)

Hope this helps
Perrin
 
Thank you. I thought I had tried that, but, maybe I did something different. Will give it another shot and let you know how it goes. Thanks!
 
You should also make sure that the tcursor is attached to the table not the field, the code you listed has it attached to the field.
 
Interesting, as that code came directly out of an article from this site. I will change that. One more quick question, just for clarification. In the setrange line, why do you list the "secondkey" field twice? I noticed that the "keyfield" was listed twice in the initial example, and just wondered why, so I could understand.

Thanks!
 
The first value is the unique value of the primary key and the second and third values are the range of the secondary key, since your range is one record both values are the same. In the original code a single value would have also worked tc.setRange(KeyField.Value)


Below is how Corel describes it in the help file
-------------------

No items (empty array) Resets range criteria to include the entire table
One item Specifies a value for an exact match on the first field of the index
Two items Specifies a range for the first field of the index
Three items The first item specifies an exact match for the first field of the index; items 2 and 3 specify a range for the second field of the index.
More than three items For an array of size n, specify exact matches on the first n-2 fields of the index. The last two array items specify a range for the n-1 field of the index.

-------------------
 
Makes sense now. Thanks for your help and your patience!
 
Ok, here is my problem. Code reads as follows and I'm sure you will be able to spot the problem right away, as my novice eyes can't:

var
roi ReportOpenInfo
rpt Report
tc tCursor
endvar

tc.attach(newclient) ; have tried newclient.db also with same issue as I will describe
tc.setRange(clientname.value,mattername.value,mattername.value)
tc.instantiateView("priv:answer")

roi.Name="newclient1.rsl"
roi.MasterTable=":priv:answer:"

rpt.open(roi)

I am getting a syntax error in the tc.attach line. It is telling me that "newclient" or "newclient.db" is an unknown identifier. Can you help?
 
What it's looking for is the name of the MRO or tableframe tied to the newclient table. Click on the MRO or tableframe and check the status bar for the name.

Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Ok, I am just stupid here. But, I have no idea how to find what you are talking about. I know how to do it in a form, but not a table. Can you help this novice out?
 
You can only use the tcursor attach() to attach to a MRO (Multi Record Object) or a tableFrame in a form. You need to have the attach point to the name of that object tcursor.attach(objectName). As langley said select either the MRO or table frame and either right click the mouse and select properties to find the name of the object or you can find the name in the status bar when it is selected. If your form doesn't have a MRO or tableFrame you won't be able to use the attach() method, if that's the case you can always add a MRO and set it to 1 row and 1 column, make the borders invisible and you will never know it's there.
 
Well, I'm confused. You do not have a tableframe or MRO on a form, or a tableview? So you are trying to associate a tCursor to a table in code? Maybe I'm missing something here, but you should use open, not attach.

In any event it looks like you are doing this the hard way. If you simply want to print the current record and it is keyed on two fields, you should run a simple query against the table using the key values in the fields and base the report on the answer.db table. Obviously, error checking should be inserted and my rendition of the query structure is a wild guess.

Code:
var

 keyVal1   string
 keyVal2   string
 qVar      query
 r         report

endvar

keyVal1 = keyVal1field.value
keyVal2 = keyVal2field.value

qVar = query

:myAlias:newclient.db | KeyField1 | KeyField 2 | Other |
                      | Check ~keyVal1 | Check ~keyVal2 | Check |

endQuery

qVar.executeQBE(":Priv:Answer.db")

r.load(":myAlias:myReport",WinStyleDefault+WinStylehidden)
r.print()
r.close()


Hope this helps,


Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
My brain is working now. Sometimes it just takes you guys to jump start it. I'll work on this some more, and as always, if I run into anymore issues, I'll be sure to let you know! : )
 
How did you get your brain working, mine hasn't worked since my son was born, I don't really notice because I also haven't slept in 12 weeks :)

Let us know if you need more help
 
Congrats on the birth, Kliot!

[OBI WAN VOICE]

You've taken you first step into a larger, more expensive, and sleepless world ...

[/OBI WAN VOICE]



Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Ok, guys, I'm about to give up! (by the way, congrats Kilot on the new addition! ). I think I am in way over my head here. I just couldn't get the original code I was trying to work since my form is set up as a single record form and has no tableframe or MRO. So, I tried the other code suggested above. It looks like this:

method pushButton(var eventInfo Event)
var
keyVal1 string
keyVal2 string
qVar query
r report
endvar

keyVal1=clientname.value
keyval2=mattername.value

qVar=query

work:newclient.db|clientname|mattername|
check |~keyval1|~keyval2|

endQuery

qVar.executeQBE(":priv:anwser.db")

r.MasterTable=":priv:answer.db"
r.load(":work:newclient.rsl",WinStyleDefault+WinStylehidden)

endMethod

(I took the print line out because I don't want to print it automatically, at least not at this point)

I tried it without the "r.MasterTable" line, and all it did was open my report in design mode. So, I added the above line, and now the error says "You have tried to access a document that is not open. An error triggered in the 'executeQBE' method on an object of query type."

This should not be that difficult, but I am just so green at this. Any other suggestions (that I can understand LOL)
 
Oh, if you want to see the report before deciding to print it, then change:

Code:
r.load(":work:newclient.rsl",WinStyleDefault+WinStylehidden)

to:

Code:
r.open(":work:newclient.rsl",WinStyleDefault,WinStyleMaximize)
r.wait()


Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Sorry, no way to edit.

That line should be:

r.open(":work:newclient.rsl",WinStyleDefault+WinStyleMaximize)



Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Ok, changed that, but still get the error "you have tried to access a document that is not open".
 
Answer is misspelled in the executeQBE statement.

Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top