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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Go to (n) record where n is thisform.text1.value

Filip Brnic

Programmer
Dec 25, 2023
43
RS
I wanna create a command button that does this, i tried alot of things and chatgpt cant help me, i looked trough the help guide but i dont get what im doing wrong
the table is roba
theres an index for field sifra
I want it to basically go to the record where N=Sifra like you would do with lets say go 2, but instead i want it to do go(N) where n is thisform.text1.value
TELL ME if i need to change structure of the table, currently its integer autoinc, i kinda need that because of the other forms, so i hope someone can make it work witw integer autoinc...
this is the code ive tried
n = THISFORM.text1.Value
IF EMPTY(n)
RETURN
ENDIF
n = VAL(n)
SELECT Roba
IF !USED("Roba")
MESSAGEBOX("Table 'Roba' is not open.")
RETURN
ENDIF

LOCATE FOR Sifra = n
 
Two things.

1. If you do a locate and find something, the form will still need to be refreshed or you will still see the OLD values. Do this with Thisform.Refresh() after the locate.

2. Whenever you do something like this, you should add some code to handle the possibility that nothing was found.

So you could do something like this:

Code:
Locate for Sifra = n
if found()
   thisform.refresh()
else
   MessageBox("Not found")
   ** put something here to go someplace else, then refresh again.
endif
 
Yet another misunderstanding:
The GO command always positions to the sequential record number, counted from top, wheras a LOCATE or SEEK compares a fieldcontent to your number.
The content of your SIFRA field may be identical to the logical record number, but normally you don't mess with recordnumbers but use a field with a unique identifier. Recordnumbers change when you delete a record snd then pack the table.
 
I didn't think he was referring to a record number. He mentioned a column named Sifra, so assuming that's the column name, and the value in the variable N is valid, the locate would work, but as I mentioned, he would not know that it worked because the screen would still need to be refreshed.

Also, there should always be a way to handle cases where the value is not found.

If it turns out he does want the absolute record position, then GO would work, but there would need to be logic BEFORE issuing GO in case they try to go past the end of the file. In that case if n <= recount() would be used before the GO.
 
Personally, I don't understand what the problem is. The record cannot be found? The form doesn't show result if the record has been found?
 
I would create an index on the table as follows:

Code:
INDEX ON BINTOC(sifra) TAG sifra

to build the index tag. Then in the InteractiveChange() event of the text box I would enter the following:

Code:
LOCAL lnSeek
IF VARTYPE(this.Value) = 'N'
    lnSeek = this.Value
ELSE
    lnSeek = CAST(this.Value TO Integer)
ENDIF
IF SEEK(BINTOC(lnSeek), "Roba", "sifra")
    thisform.grdMyGrid.Refresh()                                && this should be your grid object
ELSE
    WAIT WINDOW "Record Not Found" WINDOW AT thisform.Height/2, thisform.Width/2 NOWAIT TIMEOUT 3     && This is optional...
ENDIF

There is not a need to have a separate commandbutton.
 
Last edited:

Part and Inventory Search

Sponsor

Back
Top