Data mode statement?

I’m trying to use the datamode statement in a procedure.

My workflow is to open one form for editing (graphics mode), decide what class of objects to select with my procedure, then run my proc with the select statement set to what I want. The selectobjects fails if the form is in graphics mode, and I was getting tired of having to manually switch to Data Mode each time before I ran my proc, so I inserted a datamode statement at the beginning of my proc, but it fails with the same runtime error:

Cannot run because there is not open data window for this database.

My question is, when is the datamode statement useful? It won’t work if the form is in Graphics Mode (which is when you would want it to work), and it would be useless attached to a button, since the form would already be in Data Mode.

It’s frustrating at times, but code will only run if there’s at least one working window open (but not necessarily visible) — a form and/or the data sheet. While a window is being constructed it obviously isn’t working. So you need to have another window open somewhere in order to be able to run code which affects forms while they are in graphics mode.

Why are you putting the form into GraphicsMode in the first place? You can select objects and modify the form without going to GraphicsMode - thus your effort to get back to DataMode.

1 Like

This is not true, this statement works just fine in graphics mode. I just tested it to make sure.

The datamode statement works just fine as long as a form window is open. If the form is in graphics mode, it switches to data mode. If it is already in data mode, there is no error, it just skips to the next statement.

There aren’t a lot of actual uses for this statement, but it will work just fine when you need it. For example you could write a procedure that made sure all of the currently open form windows are in data mode, not graphics mode.

You can write a procedure that switches into Graphics Mode, performs some operation, then switches back into Data Mode. However, this isn’t really useful because for the most part anything you might want to do in graphics mode can be done in data mode.

In general, you can’t trigger a procedure when you’re in Graphics Mode, so that limits the usefulness of this statement. But you can do this if you write your own custom Constructor, and you could also write hotkeys that work in graphics mode. I don’t think writing custom Constructors is documented in the Panorama Help, but it is described in one of the Intensive Training Videos.