Open a form to a blank record

D

DaveF

I have a button on a parent form that when clicked opens a child form
(popup) and displays a specified record.

The parent form supplies the id field (stLinkCriteria) for the record that
is to be opened in the child as:

DoCmd.OpenForm stDocName, , , stLinkCriteria

But if there is no related record, the button click throws an error.

If there is no related record I would like to display a blank child form.
Or at least a message box saying there is no related record.

Can anyone give me some pointers on how to do this?

Thanks
Dave
 
G

Graham Mandeno

Hi Dave

What does "throws an error" mean? What error? What is the message?

If your stLinkCriteria is, for example, "EmployeeID=99", and there is no
such employee, then the new form should open on a blank record *unless*
AllowAdditions is turned off, in which case you will get a blank form.

If you are getting an error then something else must be wrong. More
information please!
 
D

DaveF

Thanks Graham

The error I get if I try to invoke the child form is a message box that
states:

Syntax error (missing operator) in query expression '[scriptid]='.

The code to open the form is:

stLinkCriteria = "[scriptid]=" & Me![scriptid]
DoCmd.OpenForm stDocName, , , stLinkCriteria


This database manages scripts which are small text files. The parent form
is basically a script record and the child form is some script detail.

The error occurs on new records. So when I move to a new record on the
parent and click the command button to invoke the child, there really isn't
a scriptid to pass to the child yet.

I am looking for some way to invoke the child without having to move off the
parent to commit the scriptid and then return to the parent to access the
child.

Perhaps I should add some code to commit the parent record (and create a
scriptid) prior to calling the child. Is this how it should be handled?

Dave


Graham Mandeno said:
Hi Dave

What does "throws an error" mean? What error? What is the message?

If your stLinkCriteria is, for example, "EmployeeID=99", and there is no
such employee, then the new form should open on a blank record *unless*
AllowAdditions is turned off, in which case you will get a blank form.

If you are getting an error then something else must be wrong. More
information please!

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

DaveF said:
I have a button on a parent form that when clicked opens a child form
(popup) and displays a specified record.

The parent form supplies the id field (stLinkCriteria) for the record that
is to be opened in the child as:

DoCmd.OpenForm stDocName, , , stLinkCriteria

But if there is no related record, the button click throws an error.

If there is no related record I would like to display a blank child form.
Or at least a message box saying there is no related record.

Can anyone give me some pointers on how to do this?

Thanks
Dave
 
G

Graham Mandeno

Hi Dave

So what you need to do is check first whether scriptid is Null (blank) and
take different action for that case:

If IsNull(Me![scriptid]) Then
' open the form at a new record
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
Else
' open the form at the current script
stLinkCriteria = "[scriptid]=" & Me![scriptid]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

DaveF said:
Thanks Graham

The error I get if I try to invoke the child form is a message box that
states:

Syntax error (missing operator) in query expression '[scriptid]='.

The code to open the form is:

stLinkCriteria = "[scriptid]=" & Me![scriptid]
DoCmd.OpenForm stDocName, , , stLinkCriteria


This database manages scripts which are small text files. The parent form
is basically a script record and the child form is some script detail.

The error occurs on new records. So when I move to a new record on the
parent and click the command button to invoke the child, there really isn't
a scriptid to pass to the child yet.

I am looking for some way to invoke the child without having to move off the
parent to commit the scriptid and then return to the parent to access the
child.

Perhaps I should add some code to commit the parent record (and create a
scriptid) prior to calling the child. Is this how it should be handled?

Dave


Graham Mandeno said:
Hi Dave

What does "throws an error" mean? What error? What is the message?

If your stLinkCriteria is, for example, "EmployeeID=99", and there is no
such employee, then the new form should open on a blank record *unless*
AllowAdditions is turned off, in which case you will get a blank form.

If you are getting an error then something else must be wrong. More
information please!

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

DaveF said:
I have a button on a parent form that when clicked opens a child form
(popup) and displays a specified record.

The parent form supplies the id field (stLinkCriteria) for the record that
is to be opened in the child as:

DoCmd.OpenForm stDocName, , , stLinkCriteria

But if there is no related record, the button click throws an error.

If there is no related record I would like to display a blank child form.
Or at least a message box saying there is no related record.

Can anyone give me some pointers on how to do this?

Thanks
Dave
 
D

DaveF

Thanks Graham


Graham Mandeno said:
Hi Dave

So what you need to do is check first whether scriptid is Null (blank) and
take different action for that case:

If IsNull(Me![scriptid]) Then
' open the form at a new record
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
Else
' open the form at the current script
stLinkCriteria = "[scriptid]=" & Me![scriptid]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

DaveF said:
Thanks Graham

The error I get if I try to invoke the child form is a message box that
states:

Syntax error (missing operator) in query expression '[scriptid]='.

The code to open the form is:

stLinkCriteria = "[scriptid]=" & Me![scriptid]
DoCmd.OpenForm stDocName, , , stLinkCriteria


This database manages scripts which are small text files. The parent form
is basically a script record and the child form is some script detail.

The error occurs on new records. So when I move to a new record on the
parent and click the command button to invoke the child, there really isn't
a scriptid to pass to the child yet.

I am looking for some way to invoke the child without having to move off the
parent to commit the scriptid and then return to the parent to access the
child.

Perhaps I should add some code to commit the parent record (and create a
scriptid) prior to calling the child. Is this how it should be handled?

Dave


Graham Mandeno said:
Hi Dave

What does "throws an error" mean? What error? What is the message?

If your stLinkCriteria is, for example, "EmployeeID=99", and there is no
such employee, then the new form should open on a blank record *unless*
AllowAdditions is turned off, in which case you will get a blank form.

If you are getting an error then something else must be wrong. More
information please!

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

I have a button on a parent form that when clicked opens a child form
(popup) and displays a specified record.

The parent form supplies the id field (stLinkCriteria) for the
record
that
is to be opened in the child as:

DoCmd.OpenForm stDocName, , , stLinkCriteria

But if there is no related record, the button click throws an error.

If there is no related record I would like to display a blank child form.
Or at least a message box saying there is no related record.

Can anyone give me some pointers on how to do this?

Thanks
Dave
 

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