Subform recordset must include new?

G

Guest

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?
 
G

Guest

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
 
S

SusanV

Ah, gotcha. You can compare the current record to a dcount:

cmdNextProd.Enabled = Me.CurrentRecord < DCount("SomeValidField",
Me.RecordSource)



albycindy said:
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

SusanV said:
In the form's OnCurrent event:
cmdNextProd.Enabled = (Me.NewRecord = False)
 
G

Guest

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


SusanV said:
Ah, gotcha. You can compare the current record to a dcount:

cmdNextProd.Enabled = Me.CurrentRecord < DCount("SomeValidField",
Me.RecordSource)



albycindy said:
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

SusanV said:
In the form's OnCurrent event:
cmdNextProd.Enabled = (Me.NewRecord = False)

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?
 
S

SusanV

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



albycindy said:
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


SusanV said:
Ah, gotcha. You can compare the current record to a dcount:

cmdNextProd.Enabled = Me.CurrentRecord < DCount("SomeValidField",
Me.RecordSource)



albycindy said:
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)

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?
 
G

Guest

Ok, I'll try again! I definitely used the "".

SusanV said:
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



albycindy said:
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


SusanV said:
Ah, gotcha. You can compare the current record to a dcount:

cmdNextProd.Enabled = Me.CurrentRecord < DCount("SomeValidField",
Me.RecordSource)



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)

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?
 
G

Guest

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.

SusanV said:
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



albycindy said:
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


SusanV said:
Ah, gotcha. You can compare the current record to a dcount:

cmdNextProd.Enabled = Me.CurrentRecord < DCount("SomeValidField",
Me.RecordSource)



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)

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?
 
S

SusanV

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>


albycindy said:
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.

SusanV said:
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



albycindy said:
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)



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)

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?
 
G

Guest

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. :)

SusanV said:
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>


albycindy said:
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.

SusanV said:
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



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)



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)

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?
 
S

SusanV

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?


albycindy said:
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. :)

SusanV said:
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>


albycindy said:
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



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)



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?
 
G

Guest

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.

SusanV said:
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?


albycindy said:
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. :)

SusanV said:
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



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)



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?
 
S

SusanV

sorry if I wasn't clear... Here's the code from my form with the debugs
added:

Private Sub Form_Current()

Debug.Print Me.CurrentRecord; DCount("PrecTitle", Me.RecordSource)

btnNext.Enabled = Me.CurrentRecord < DCount("PrecTitle",
Me.RecordSource)
btnPrev.Enabled = Not (Me.CurrentRecord = 1)

End Sub

Now as I scroll through the form, I can see whether the values are being
populated correctly - if I'm on, according to the navigation bar, record 1
of 7, then scroll to the last record, the debug widnow will show

2 7
3 7
4 7
5 7
6 7
7 7
8 7


When i hit record 7 (shown in the window as 7 7) the Next button becomes
greyed out untill I scroll back to 6 or lower.

I hope that's a bit clearer!




albycindy said:
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.

SusanV said:
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?


albycindy said:
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



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?
 
S

SusanV

By the way - 8 7 indicates the blank form for a new record - didn't want
to confuse you! When you get to a new record on the form the navigation bar
will show, for instance, 8 of 8 - but the recordsource still only has 7
records, as nothing has been saved yet.

;-)


SusanV said:
sorry if I wasn't clear... Here's the code from my form with the debugs
added:

Private Sub Form_Current()

Debug.Print Me.CurrentRecord; DCount("PrecTitle", Me.RecordSource)

btnNext.Enabled = Me.CurrentRecord < DCount("PrecTitle",
Me.RecordSource)
btnPrev.Enabled = Not (Me.CurrentRecord = 1)

End Sub

Now as I scroll through the form, I can see whether the values are being
populated correctly - if I'm on, according to the navigation bar, record 1
of 7, then scroll to the last record, the debug widnow will show

2 7
3 7
4 7
5 7
6 7
7 7
8 7


When i hit record 7 (shown in the window as 7 7) the Next button becomes
greyed out untill I scroll back to 6 or lower.

I hope that's a bit clearer!




albycindy said:
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.

SusanV said:
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



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?
 
G

Guest

I don't get a Debug window :(

I put it in my Current Event, changed PrecTitle to Product, but whenever the
Current event fired I got an error saying, "You cancelled the previous
action" What the...? I don't think I'm skilled enough to help you with this
Susan - I feel like a dufus!

SusanV said:
sorry if I wasn't clear... Here's the code from my form with the debugs
added:

Private Sub Form_Current()

Debug.Print Me.CurrentRecord; DCount("PrecTitle", Me.RecordSource)

btnNext.Enabled = Me.CurrentRecord < DCount("PrecTitle",
Me.RecordSource)
btnPrev.Enabled = Not (Me.CurrentRecord = 1)

End Sub

Now as I scroll through the form, I can see whether the values are being
populated correctly - if I'm on, according to the navigation bar, record 1
of 7, then scroll to the last record, the debug widnow will show

2 7
3 7
4 7
5 7
6 7
7 7
8 7


When i hit record 7 (shown in the window as 7 7) the Next button becomes
greyed out untill I scroll back to 6 or lower.

I hope that's a bit clearer!




albycindy said:
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.

SusanV said:
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



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?
 
S

SusanV

You can take the immediate window out of the VBE so it's in its own window,
then position it on your screen so that you can see both it and the form. Or
you can open the VBE behind the form, run through the records, then check
the immediate window. If the immediate window isn't visible at all in the
VBE, go to View>>Immediate window or hit CTRL + G

Can you copy/paste your On Current code? Something is flaky there...


albycindy said:
I don't get a Debug window :(

I put it in my Current Event, changed PrecTitle to Product, but whenever
the
Current event fired I got an error saying, "You cancelled the previous
action" What the...? I don't think I'm skilled enough to help you with
this
Susan - I feel like a dufus!

SusanV said:
sorry if I wasn't clear... Here's the code from my form with the debugs
added:

Private Sub Form_Current()

Debug.Print Me.CurrentRecord; DCount("PrecTitle", Me.RecordSource)

btnNext.Enabled = Me.CurrentRecord < DCount("PrecTitle",
Me.RecordSource)
btnPrev.Enabled = Not (Me.CurrentRecord = 1)

End Sub

Now as I scroll through the form, I can see whether the values are being
populated correctly - if I'm on, according to the navigation bar, record
1
of 7, then scroll to the last record, the debug widnow will show

2 7
3 7
4 7
5 7
6 7
7 7
8 7


When i hit record 7 (shown in the window as 7 7) the Next button
becomes
greyed out untill I scroll back to 6 or lower.

I hope that's a bit clearer!




albycindy said:
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?
 
B

BruceM

This is based on a reply to a question of mine in this group some while ago.
I find that I need to add a line of code before the Enabled code:

Me.RecordsetClone.MoveLast

cmdPrev.Enabled = Not Me.CurrentRecord = 1
cmdNext.Enabled = (Me.CurrentRecord = 1 And Me.Recordset.RecordCount >
1) _
Or Me.CurrentRecord < Me.Recordset.RecordCount

Also, this code makes allowance for enabling cmdNext when you are at the
first of several records.

albycindy said:
I don't get a Debug window :(

I put it in my Current Event, changed PrecTitle to Product, but whenever
the
Current event fired I got an error saying, "You cancelled the previous
action" What the...? I don't think I'm skilled enough to help you with
this
Susan - I feel like a dufus!

SusanV said:
sorry if I wasn't clear... Here's the code from my form with the debugs
added:

Private Sub Form_Current()

Debug.Print Me.CurrentRecord; DCount("PrecTitle", Me.RecordSource)

btnNext.Enabled = Me.CurrentRecord < DCount("PrecTitle",
Me.RecordSource)
btnPrev.Enabled = Not (Me.CurrentRecord = 1)

End Sub

Now as I scroll through the form, I can see whether the values are being
populated correctly - if I'm on, according to the navigation bar, record
1
of 7, then scroll to the last record, the debug widnow will show

2 7
3 7
4 7
5 7
6 7
7 7
8 7


When i hit record 7 (shown in the window as 7 7) the Next button
becomes
greyed out untill I scroll back to 6 or lower.

I hope that's a bit clearer!




albycindy said:
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?
 

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