SetValue macro not setting value

M

mbaycura

I'm trying to use a macro that will run when a button is clicked that will
open a different form and set the ID value of the new forms record to the
same value as the original form ID number.

I created a macro group called "NewNPI" which is called when the button is
clicked.
this macro is the following.
SetTempvar ---- NPITemp, [ID]
OpenForm ---- NPI Entry, Form,,,,Normal
SearchForRecord ----,,First, ID=[TempVars]![NPITemp]
condition [ID]<0 ----- SetValue ---- [ID], [TempVars]![NPITemp]
RemoveTempVar --- NPITemp

the idea is that it sets a temp variable to the original forms record ID
then opens the new form, goes to a new record, then searches to see if a
record already exists with that number, if this comes back false, according
to the help this should stay on the current record which would be new. then
sets the current, new record ID to the temp var and removes the tempvar. I
had a condition that was if ID<1 so that it would not overwrite the record ID
if it does find one with the Tempvar value. But with or without the
condition it goes to the new record and stays there without updating the ID
of the new form properly with TempVar before removing it.

The key column is called ID for both the original form and the new form.
When I try to use SetValue with the full path [NPI Entry].[ID] or [NPI
Entry]![ID], I get an automation error. When I step through as is above
there are no errors, but the vaule in ID does not populate. However I have a
dummy unbound text box that populates correctly with the original forms ID
record value.

Help, PLEASE!
thanks.
 
K

KARL DEWEY

A lot simpler way is to use the double-click to call the macro. Macro to
open form in Data Mode - Add (creates a new record).
Then SetValue --
Item - [Forms]![FirstForm]![ID]
Expression - [Forms]![SecondForm]![ID]
 
M

mbaycura

I can't just add a form because I need to check if one already exists with
that number. If it does then I'm either going to have it cancel the request
or go to that record for editing (I know what I had posted will not quite do
that as is), but my first step was just to get it to add and pull the right
number.

Your feedback did solve my first problem though, by using the full syntax of
[Forms]![NPI Entry]![ID] I got it to pull a new record and set the right
value.

However, now I'm trying to get the 2nd part to work with a combination of
searchforrecord and gotorecord, but not having much luck. I'm not sure how
the SearchForRecord works, what does it return, a record in virtual memory, a
boolean, or is it supposed to make the result of the search the current
record? If it's supposed to do the latter I'm doing something wrong because
that's not what I get.

Anyway, thanks for the feedback it was quite helpful. This is my first
database, so syntax has been a big issue. I usually have the logic ok, but
can't always get it to work right because I don't have all the different
syntax correct.


KARL DEWEY said:
A lot simpler way is to use the double-click to call the macro. Macro to
open form in Data Mode - Add (creates a new record).
Then SetValue --
Item - [Forms]![FirstForm]![ID]
Expression - [Forms]![SecondForm]![ID]
--
KARL DEWEY
Build a little - Test a little


mbaycura said:
I'm trying to use a macro that will run when a button is clicked that will
open a different form and set the ID value of the new forms record to the
same value as the original form ID number.

I created a macro group called "NewNPI" which is called when the button is
clicked.
this macro is the following.
SetTempvar ---- NPITemp, [ID]
OpenForm ---- NPI Entry, Form,,,,Normal
SearchForRecord ----,,First, ID=[TempVars]![NPITemp]
condition [ID]<0 ----- SetValue ---- [ID], [TempVars]![NPITemp]
RemoveTempVar --- NPITemp

the idea is that it sets a temp variable to the original forms record ID
then opens the new form, goes to a new record, then searches to see if a
record already exists with that number, if this comes back false, according
to the help this should stay on the current record which would be new. then
sets the current, new record ID to the temp var and removes the tempvar. I
had a condition that was if ID<1 so that it would not overwrite the record ID
if it does find one with the Tempvar value. But with or without the
condition it goes to the new record and stays there without updating the ID
of the new form properly with TempVar before removing it.

The key column is called ID for both the original form and the new form.
When I try to use SetValue with the full path [NPI Entry].[ID] or [NPI
Entry]![ID], I get an automation error. When I step through as is above
there are no errors, but the vaule in ID does not populate. However I have a
dummy unbound text box that populates correctly with the original forms ID
record value.

Help, PLEASE!
thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top