Newbie - Is this correct syntax

M

M Davidson

Hello all,

Is this correct syntax to refer to a value in a text box on a form that
is not the current active form? It's being called in the code attached to
another form that is the current active form. (This is where the code is
failing and I can't figure out why.)

Holder = Forms!vForm!Placeholder.Value

Thanks,
Mike Davidson
 
D

DebbieG

I find this file very helpful:
http://www.mvps.org/access/forms/frm0031.htm

I don't think you need the .Value.

And make sure you're using the field NAME , not the Control Source.

HTH,
Debbie


| Hello all,
|
| Is this correct syntax to refer to a value in a text box on a form that
| is not the current active form? It's being called in the code attached to
| another form that is the current active form. (This is where the code is
| failing and I can't figure out why.)
|
| Holder = Forms!vForm!Placeholder.Value
|
| Thanks,
| Mike Davidson
 
M

M.L. Sco Scofield

With the information you provided, the line is just fine.

We're going to need more information to help you.

The best piece of information would be what you mean by "...failing..."

Are you getting an error message? If this is a code line, is it red? Does
your code compile?

Another piece of information that might be nice is where is this line?

What is "Holder"? A text box? A variable? If so, what type?

More information please...

Sco

M.L. "Sco" Scofield, Microsoft Access MVP, MCSD, MCP, MSS, A+
Denver Area Access Users Group Vice President www.DAAUG.org
MS Colorado Events Administrator www.MSColoradoEvents.com
Useful Metric Conversion #18 of 19: 8 nickels = 2 paradigms (My personal
favorite)
Miscellaneous Access and VB "stuff" at www.ScoBiz.com
 
D

Dirk Goldgar

M Davidson said:
Hello all,

Is this correct syntax to refer to a value in a text box on a
form that is not the current active form? It's being called in the
code attached to another form that is the current active form. (This
is where the code is failing and I can't figure out why.)

Holder = Forms!vForm!Placeholder.Value

Thanks,
Mike Davidson

If "vForm" is actually the literal name of a form, and that form is open
at the time the statement is executed, the statement appears to be
syntactically correct. If, on the other hand "vForm" is a *variable*
that holds the name of the form, then the syntax would have to be

Holder = Forms(vForm)!Placeholder.Value

And if "vForm" is the name of an object variable that holds a reference
to the open form, then just

Holder = vForm!Placeholder.Value

would be sufficient. Beyond that I can't say without more information.
 
M

M Davidson

M.L. Sco Scofield said:
With the information you provided, the line is just fine.

We're going to need more information to help you.

The best piece of information would be what you mean by "...failing..."

Are you getting an error message? If this is a code line, is it red? Does
your code compile?

Another piece of information that might be nice is where is this line?

What is "Holder"? A text box? A variable? If so, what type?

<<SNIP>>


The problem I'm trying to address is : I have criteria that will change the
value of a text box on the form AND the same criteria restricts user
navigation through the form.

I'm attempting to write a case select procedure for a form to restrict
user movement within the table. Depending on what criteria are met I want
to enable/disable the record navigation buttons.
IN ADDITION, the same criteria will also change the value of a text box
control on the same form. It appears that I'm not assigning my variables
correctly, but I'm not sure.

Key.value is the serial number for the table tblScores. This is the same
table that the form's record source is assigned. So Key.value will be the
serial number on the current record being edited/entered. I used
DoCmd.GoToRecord , , acNewRec assigned to the form's open event to ensure
that the form opened on a new record.

Placeholder.value is a number that is assigned to an unbound control on an
unbound form called vForm. This is intended to be a hidden form to hold
variables for use at run time. I assigned the value to Placeholder.value by
using the domain aggregate function dLast to pull the last serial number
used to enter data prior to the current instance of frmScores being opened.

I want the user to be able to go forward and backwards through the records
he is currently entering, but I don't want him to be able to go back beyond
them or before them. The example below is intended to allow the user to
enter 5 scores only and force the change of category in txtCategory.value
on each record change. Once the user gets to the 5th record he can only go
back to edit or click the btnFinished button, which opens a completely
seperate form attached to another table.

The code fails when the form is opened by another form and the editor
highlights the line
"Holder = Forms!vForm!Placeholder.Value" in yellow.

another thing, I thought this one up on my own ( the navigation on math from
the serial number), so there's a real good possibility that the whole
concept is flawed. If it is let me know.

The code is attached to the Form's "On Update" event?

If there's a better way to do this please advise the general concept and
I'll get to reading.

Heres's the code:

Dim Number
Dim Holder

'assign current record's serial number to Number

Number = Me!Key.Value

'assign last serial number from the previous set of 5 scores
'(Placeholder.value) to Holder

Holder = Forms!vForm!Placeholder.Value

Select Case Number
Case Holder 'this is equal to the last record already entered
Me!btnBack.Enabled = No
Me!btnFinished.Enabled = No
Me!btnForward.Enabled = Yes
Me!txtCategory.Value = Something's wrong

'First record in set

Case Holder + 1
Me!btnBack.Enabled = No
Me!btnFinished.Enabled = No
Me!btnForward.Enabled = Yes
Me!txtCategory.Value = Cat1

'Second record in set

Case Holder + 2
Me!btnBack.Enabled = No
Me!btnFinished.Enabled = No
Me!btnForward.Enabled = Yes
Me!txtCategory.Value = Cat2
Case Holder + 3
Me!btnBack.Enabled = Yes
Me!btnFinished.Enabled = No
Me!btnForward.Enabled = Yes
Me!txtCategory.Value = Cat3
Case Holder + 4
Me!btnBack.Enabled = Yes
Me!btnFinished.Enabled = No
Me!btnForward.Enabled = Yes
Me!txtCategory.Value = Cat4
Case Holder + 5
Me!btnBack.Enabled = Yes
Me!btnFinished.Enabled = Yes
Me!btnForward.Enabled = No
Me!txtCategory.Value = Cat5

Case Else
Debug.Print "Value not represented."


End Select
 
D

Dirk Goldgar

M Davidson said:
The code fails when the form is opened by another form and the editor
highlights the line
"Holder = Forms!vForm!Placeholder.Value" in yellow.

Asking again, on Sco's behalf: What do you mean by "the code fails"?
Do you get an error message? If so, what is it? Is there an error
number associated with the message? If so, what is the number?
The code is attached to the Form's "On Update" event?

Um, there is no "On Update" event. There's a BeforeUpdate event, and
there's an AfterUpdate event. Is it one of those?
If there's a better way to do this please advise the general concept
and I'll get to reading.

You mention using DLast() to get the "last" serial number entered
previously. You should be aware that DLast() can't really be relied on
to give you information from the last record entered, because the
concept of "last" is only meaningful when some field-based ordering has
been applied. Would these serial numbers be assigned as sequentially
ascending numbers? If so, then DMax() might give you what you want. If
not, then the only real way to know which is the last one entered is to
have a date-time stamp field in the table to record when a record was
entered. Then you could get the serial number from the record with the
most recent entry time.
 
M

M.L. Sco Scofield

Hi Mike,

Sorry to take so long getting back. I was hoping you'd answer Dirk's request
before I had time to get back to this.

I don't have the time to analyze what you're doing, so let's focus on your
specific problem.

Based on what you have said, there is nothing I can see wrong with the line
you are getting your error on.

One thing that was not entirely clear was "...Placeholder.value is a number
that is assigned to an unbound control on an
unbound form called vForm..." Is "Placeholder" a text box on your form?

As I asked before, (and Dirk also asked,) what is the error message you are
getting?

Maybe with the "exact" error message you are getting, Dirk or I can make a
more educated guess as to what the problem is.

Sco

M.L. "Sco" Scofield, Microsoft Access MVP, MCSD, MCP, MSS, A+
Denver Area Access Users Group Vice President www.DAAUG.org
MS Colorado Events Administrator www.MSColoradoEvents.com
Useful Metric Conversion #18 of 19: 8 nickels = 2 paradigms (My personal
favorite)
Miscellaneous Access and VB "stuff" at www.ScoBiz.com
 

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