I'm lost! Am I putting the debug.print thing in the immediate window
with
my
code immediately after it? I was just testing the ones you asked me to.
:
It means that the variable hasn't been populated yet. Did you put the
debug.prints in line with your code or type them into the window? They
need
to be inline with the code and should be in the form's OnCurrent
event.
If
you then scroll through the form, you should be able to view the
results
in
the immediate window. If the debugs are inline with your code, what's
the
entire code you currently have, and what event are you using? Which
debug
print line caused the error?
I'm more than willing to satisfy your curiosity!
I tried both of those in the Immediate window and the following
error
was
returned.
Compile Error: Variable not yet created in this context
I hope you know what that means, because I don't.
:
So weird! I'm curious - have you used debug.print to compare the 2
values
in
the immediate window? I'm just wondering if the 2 values you're
comparing
are being populated correctly...
debug.print me.currentrecord
'should show the same # as in navigation bar
debug.print DCount("PrecTitle", Me.RecordSource)
'should show the total number of records in the navigation bar
If I'm beating a dead horse and you've given up on this that's
fine.
I'm
just stubborn <grin>
Nope! Damn...for some reason it doesn't work, I've tried on many
fields,
making sure I have the correct name. Oh well, I might just settle
for
the
other code because the Previous button isn't that much of a big
deal, I
was
just going for perfectionism!
Thanks Susan - everytime I ask something, even if I don't get a
perfect
solution, I learn something.
:
Huh, odd that it isn't working for you - I use this code on a
couple
of
different forms. I use Me.recordsource (without quotes) as the
domain
because this form allows filters. I hide the Navigation bar from
the
users
and have add new buttons etc. This is my code, and PrecTitle is
a
field
in
the table I use as a datasource - note that it is enclosed in
double
quotes.
Perhaps you're trying to use the control name in the from rather
than
the
field name from the recordsource?
Private Sub Form_Current()
btnNext.Enabled = Me.CurrentRecord < DCount("PrecTitle",
Me.RecordSource)
btnPrev.Enabled = Not (Me.CurrentRecord = 1)
End Sub
message
Thanks for your help Susan. I tried using a few valid fields
(one's
that
would always be filled in) but it's still enabling Next when
there
is a
potential record. I found this code, but that always enables
my
Previous
button (aaargh! seems like I can't find the middle ground!)
Can
you
see
why?
Private Sub Form_Current()
Dim rst As DAO.Recordset
Dim lngCount As Long
Set rst = Me.RecordsetClone
With rst
.MoveFirst
.MoveLast
lngCount = .RecordCount
End With
If Me.CurrentRecord = lngCount Then
Me.cmdNextProd.Enabled = False
Me.cmdPrevProd.Enabled = True
ElseIf Me.CurrentRecord = 1 Then
Me.cmdNextProd.Enabled = True
Me.cmdPrevProd.Enabled = False
Else
Me.cmdNextProd.Enabled = True
Me.cmdPrevProd.Enabled = True
End If
End Sub
:
Ah, gotcha. You can compare the current record to a dcount:
cmdNextProd.Enabled = Me.CurrentRecord <
DCount("SomeValidField",
Me.RecordSource)
message
This works when I'm on the potential record (primary key is
on
[Autonumber])
but now when I'm on the last real record, a record with a
number
and
information. Basically, I need it to check whether the NEXT
record
is a
new
record or not not the CURRENT record.
Thanks
:
In the form's OnCurrent event:
cmdNextProd.Enabled = (Me.NewRecord = False)
message
I'm trying to disable my Previous and Next buttons based
on
the
following
code:
Sub Form_Current()
cmdPrevProd.Enabled = Not Me.CurrentRecord = 1
cmdNextProd.Enabled = Me.CurrentRecord <
Me.Recordset.RecordCount
End Sub
It works fine for Previous but not for Next. It is
always
enabled
because
I
have the Allow Additions property of the subform set to
Yes. I
tried
changing
this to No but then my Next button is disabled when
there
IS
more
than
one
real record, not just a potential new record.
I have created a button to Add a new record (cmdAddProd)
but
this
will
only
work if the Allow Addtions property is set to Yes.
Any ideas on how to solve this?