August 28, 200421 yr Hi, In search mode, when no records are found, we can use the Get ( LastError )=401. But within a relationship with the Go To Related Records script? How can I know that no record is related ? It's weird, because if the user clicks on a button with the Go To Related records script, and that no record is shown, then nothing happen. Chris
August 28, 200421 yr One great advantage of relationships is that you can check BEFORE you use them. First, you need a field that you're sure has data in it in the related table; or at least would have data for that relationship, such as the right hand key of the relationship. If [ not IsEmpty(relationship::field) ] Go To Related Record ["relationship"] Else Do whatever if no match End If
August 29, 200421 yr Author Thanks Fenton for your interesting idea. But in this case, I've forgotten to specify that it is a self joined relationship and a ">" type. The right hand key is thus always filled. By the way, maybe I can explain why I use this scheme : I'm reluctant to use the perform find function, because I think relationships are faster. But it may be a false idea. What do you think ?
August 29, 200421 yr It doesn't make any difference. If there's none greater, the related field is empty, when you try to access it via the relationship. Try it. Yes, relationships are faster.
September 28, 200421 yr Author Ah... I found something. Just use the ErrorCode 101 ("record is missing"). set Error Capture (On) Go to related record if (Get(LastError)=101) beep : "not found" end if
September 28, 200421 yr No need to go to a related record when none exist. It's easier to do as Fenton wrote, If [not IsEmpty(relationship::serial)] Go to Related Record [show only related; relationship] Else Show Custom Dialog ["No related records exist."] End If If there are one or more related records, then relationship::serial (the right-hand key) will not be empty.
September 29, 200421 yr I use Count (relationship::keyfield ) > 0, but it has been suggested that this is slower.
September 29, 200421 yr Yes, if there are multiple related records, then Count would be slower. IsEmpty only checks the first related field and doesn't have to count anything, just return a boolean. I assume it would only need to test whether Left( field; 1 ) is empty. But I'm not sure if it does test the entire field. Either way, it would theoretically be faster.
Create an account or sign in to comment