Problem with "Goto New Record" in a subform.

F

Frank Martin

I wonder what I'm doing wrong here:

The subform name is 'CreditorsSUB' and the data therein based on
'QryCreditorTrans'.

In the properties dialogue I have set the 'Data Entry' to 'Yes' but still
the form refuses to display a new blank record.

I've had to solve the problem by using the wizard to place a button on the
subform with the "GotoLast" option (there being no "GotoNew") and then
altering the code behind the wizard's button as follows:

***
Private Sub Command23_Click()
On Error GoTo Err_Command23_Click

DoCmd.GoToRecord , , acLast
DoCmd.GoToRecord , , acNext

Exit_Command23_Click:
Exit Sub

End Sub

***
And now when I press this button I get the desired result.

But this seems a round-about way of doing it, so can someone help me with a
better way? Regards Frank
 
A

Allen Browne

Assuming the button is in the subform (which means that it has focus), this
should work:

If Me.Dirty Then 'Save any edits first.
Me.Dirty = False
End If
If Not Me.NewRecord Then
RunCommand acCmdRecordsGotoNew
End If
 
F

Frank Martin

Thanks, I have altered this so that the following code is activated on the
"on enter" property of the subform with:
"RunCommand acCmdRecordsGotoNew"

The subform in question is linked to a Combobox with the Child/Master
properties of the subform and this will give all the records for the name
selected in the combobox.

However if there are no records for a particular name I get an error message
"RunCommand acCmdRecordsGoToNew is not available now."

How can I get the new record in the subform even if there are no records in
it.

PS I have already set the DataEntry property for the subform datasheet to
'Yes' but this has no effect - is there some occasions when this will not
work?
 
A

Allen Browne

If the form's DataEntry property is set to Yes, no existing record will
appear, and you will initially see *only* the new record row (unless no new
record can be added, in which case the detail section will go completely
blank.)

If you have only the new record row, then I fail to see the point of trying
to move to the new record row, because you are already there. Is is possible
that you are seeing the Default Value entries in the contorls, and not
recognising that you are already at the new record row?
 
F

Frank Martin

My point is that I cannot get the DataEntry propery to work for the table
when in a subform.

It works well when the form is accessed directly in the form-objects screen,
and fails completely when this table is within the subform.

This has never happened before.

I amtrying to circumvent this problem by using the "RunCommand
acCmdRecordsGoToNew" and similar codes, though I would rather not.

Regatds, Frank
 
A

Allen Browne

Okay: you want to display *no* existing records in the subform, except the
one(s) the user is entering while at the main record. Then when the main
form moves record, all records in the subform should be suppressed again?

Unusual request, but try turning the subform's DataEntry off again (since it
does not work as expected), and set its RecordSource to a query that returns
no records. Example:
SELECT Table1.* FROM Table1 WHERE (False);
Naturally this returns no records, so you are instantly taken to the new
record. If you enter a record stays visible until you move record. Is that
the behavior you wanted?
 
F

Frank Martin

Thanks, but I need something for this and other forms, such as:

*****
Private Sub CreditorsSuppTxnsSUB_Enter()

If Me.NewRecord = True Then
Me.[CreditorsSuppTxnsSUB].[Form]![AddressesID].SetFocus
Else
DoCmd.RunCommand acCmdRecordsGoToNew
Me.[CreditorsSuppTxnsSUB].[Form]![AddressesID].SetFocus
End If
*******

but this dosn't work!

Can you see anything wrong with the above?
Regards.


End Sub
 
A

Allen Browne

Frank, your code tests whether the main form is at a new record.

Did you intend this:

Private Sub CreditorsSuppTxnsSUB_Enter()
Me.CreditorsSuppTxnsSUB.Form!AddressesID.SetFocus
If Not Me.CreditorsSuppTxnsSUB.Form.NewRecord Then
DoCmd.RunCommand acCmdRecordsGoToNew
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Frank Martin said:
Thanks, but I need something for this and other forms, such as:

*****
Private Sub CreditorsSuppTxnsSUB_Enter()

If Me.NewRecord = True Then
Me.[CreditorsSuppTxnsSUB].[Form]![AddressesID].SetFocus
Else
DoCmd.RunCommand acCmdRecordsGoToNew
Me.[CreditorsSuppTxnsSUB].[Form]![AddressesID].SetFocus
End If
*******

but this dosn't work!

Can you see anything wrong with the above?
Regards.


End Sub
Allen Browne said:
Okay: you want to display *no* existing records in the subform, except
the one(s) the user is entering while at the main record. Then when the
main form moves record, all records in the subform should be suppressed
again?

Unusual request, but try turning the subform's DataEntry off again (since
it does not work as expected), and set its RecordSource to a query that
returns no records. Example:
SELECT Table1.* FROM Table1 WHERE (False);
Naturally this returns no records, so you are instantly taken to the new
record. If you enter a record stays visible until you move record. Is
that the behavior you wanted?
 
F

Frank Martin

Yes, thank you very much; this works like a dream.
Regards, Frank




Allen Browne said:
Frank, your code tests whether the main form is at a new record.

Did you intend this:

Private Sub CreditorsSuppTxnsSUB_Enter()
Me.CreditorsSuppTxnsSUB.Form!AddressesID.SetFocus
If Not Me.CreditorsSuppTxnsSUB.Form.NewRecord Then
DoCmd.RunCommand acCmdRecordsGoToNew
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Frank Martin said:
Thanks, but I need something for this and other forms, such as:

*****
Private Sub CreditorsSuppTxnsSUB_Enter()

If Me.NewRecord = True Then
Me.[CreditorsSuppTxnsSUB].[Form]![AddressesID].SetFocus
Else
DoCmd.RunCommand acCmdRecordsGoToNew
Me.[CreditorsSuppTxnsSUB].[Form]![AddressesID].SetFocus
End If
*******

but this dosn't work!

Can you see anything wrong with the above?
Regards.


End Sub
Allen Browne said:
Okay: you want to display *no* existing records in the subform, except
the one(s) the user is entering while at the main record. Then when the
main form moves record, all records in the subform should be suppressed
again?

Unusual request, but try turning the subform's DataEntry off again
(since it does not work as expected), and set its RecordSource to a
query that returns no records. Example:
SELECT Table1.* FROM Table1 WHERE (False);
Naturally this returns no records, so you are instantly taken to the new
record. If you enter a record stays visible until you move record. Is
that the behavior you wanted?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

My point is that I cannot get the DataEntry propery to work for the
table
when in a subform.

It works well when the form is accessed directly in the form-objects
screen,
and fails completely when this table is within the subform.

This has never happened before.

I amtrying to circumvent this problem by using the "RunCommand
acCmdRecordsGoToNew" and similar codes, though I would rather not.

Regatds, Frank


If the form's DataEntry property is set to Yes, no existing record
will
appear, and you will initially see *only* the new record row (unless
no
new record can be added, in which case the detail section will go
completely blank.)

If you have only the new record row, then I fail to see the point of
trying to move to the new record row, because you are already there.
Is is
possible that you are seeing the Default Value entries in the
contorls,
and not recognising that you are already at the new record row?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Thanks, I have altered this so that the following code is activated
on
the "on enter" property of the subform with:
"RunCommand acCmdRecordsGotoNew"

The subform in question is linked to a Combobox with the Child/Master
properties of the subform and this will give all the records for the
name
selected in the combobox.

However if there are no records for a particular name I get an error
message "RunCommand acCmdRecordsGoToNew is not available now."

How can I get the new record in the subform even if there are no
records
in it.

PS I have already set the DataEntry property for the subform
datasheet to
'Yes' but this has no effect - is there some occasions when this will
not
work?





Assuming the button is in the subform (which means that it has
focus),
this should work:

If Me.Dirty Then 'Save any edits first.
Me.Dirty = False
End If
If Not Me.NewRecord Then
RunCommand acCmdRecordsGotoNew
End If


I wonder what I'm doing wrong here:

The subform name is 'CreditorsSUB' and the data therein based on
'QryCreditorTrans'.

In the properties dialogue I have set the 'Data Entry' to 'Yes' but
still
the form refuses to display a new blank record.

I've had to solve the problem by using the wizard to place a
button on
the
subform with the "GotoLast" option (there being no "GotoNew") and
then
altering the code behind the wizard's button as follows:

***
Private Sub Command23_Click()
On Error GoTo Err_Command23_Click

DoCmd.GoToRecord , , acLast
DoCmd.GoToRecord , , acNext

Exit_Command23_Click:
Exit Sub

End Sub

***
And now when I press this button I get the desired result.

But this seems a round-about way of doing it, so can someone help
me
with a
better way? Regards Frank
 

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