Refresh form to show information entered via a popup

H

HeislerKurt

I have main form, frmPatients, based on tblPatients. The main form
shows the patient's name, DOB, etc. These controls are not enabled.

I created my own toolbar with an item, "Add new patient." Clicking
this opens up a model form, frmNewPatient (also based on tblPatients;
Data Entry set to "Yes"). The user enters information for the new
patient (name, DOB, etc.), and then clicks a save button.

When frmNewPatient pops up, frmPatients moves to a new record using:

###

Private Sub Form_Open(Cancel As Integer)
Forms!frmPatients.SetFocus
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
DoCmd.GoToRecord , , acNewRec
End Sub

###

But when the user clicks the Save button on frmNewPatient, the new
record is added to the table but frmPatients is not refreshed to show
the new information. What should I add to the code to do this?

###

Private Sub cmdSavePatient_Click()
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
DoCmd.Close
End Sub

###

I'm going to add an "Edit Patient" button on the toolbar, so I'll need
similar handing for that, too.

Thanks.

Kurt
 
S

Steve

Why are you going to all this trouble? Why are the controls disabled on
frmPatients? Why not make the controls on frmPatients enabled then all you
need do is click the New Record button in the navigation buttons and you can
add a new patient. frmPatient will then be on the new patient record like
you want.

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)
 
D

Damon Heron

Just use one form and add a New Record button on it. Here is the code:

Private Sub cmdAddNew_Click()
On Error GoTo Err_cmdAddNew_Click
Me.AllowAdditions = True
Me.yourcontrols.Enabled = True
Me.yourcontrols.Enabled = True
etc.....


DoCmd.GoToRecord , , acNewRec

Exit_cmdAddNew_Click:
Exit Sub

Err_cmdAddNew_Click:
MsgBox Err.Description
Resume Exit_cmdAddNew_Click

End Sub

Then, in the form's current event, add this:

Private Sub Form_Current()
If Me.NewRecord Then
'just arrived at a new record
Else
Me.cmdAddNew.SetFocus
Me.AllowAdditions = False
Me.yourcontrols.Enabled = False
Me.yourcontrols.Enabled = False
End If
End Sub

This keeps previous records disabled so the user can only add a new record,
not go back and change previous records. If you don't care about that, then
eliminate the Current event.


HTH
Damon
 
B

BruceM

Setting Allow Edits and Allow Deletions to No may do what is needed without
having to use a separate form for new records, and without needing code to
enable/disable controls and so forth. If you need controls to be grayed out
I think you will need to loop through the controls in the form's Current
event, changing the properties based on whether or not it is a new record
(or specify the properties individually for each control). If you simply
want to prevent changes, setting the properties should do the trick.
 
H

HeislerKurt

I'd rather not enable/disable the controls as needed, or setting the
Allow Edits, Additions, etc. properties.

I'm doing this mainly for GUI purposes and to maximize screen real
estate on the main form.

I also wasn't clear in my first post.

On the main form, I'm using a lot of calculated text boxes to
concatenate information from several fields about the patient. I'm
doing this mainly for GUI purposes, as it allows to me to show a lot
of basic patient information (name, demographics, etc.) in a small row
across the top of the form (in the Form Header), where it will stay -
not easily edited (but editable just in case) - as the user works
through various subforms below. Putting the *actual* controls in this
same area along the top will take up too much screen real estate.

Hoping this makes sense,

Kurt
 
D

Dale Fye

Kurt,

1. Get rid of the code in the New Patients open event.

2. On the main form, in the code behind your "NewPatient" command button,
put something like:

Private Sub cmdNewPatient_Click

Dim rs as dao.recordset

'I probably don't have the right number of commas here
Docmd.openform "frmNewPatient",,,,,acDialog

'This code wont run until the NewPatient form is hidden or closed

'You will need a function IsLoaded to determine whether the NewPatient
'form is loaded. You can search this forum for the function if you don't
'already have it.
If isloaded("frmNewPatient") then
me.requery 'This will add the new record to the main form
Set rs = me.recordsetclone
rs.FindFirst "[PatientID] = " & Forms("frmNewPatient").txt_Patient_ID
if not rs.nomatch then me.bookmark = rs.bookmark
rs.close
set rs = nothing
docmd.close acform, "frmNewPatient"
endif
End sub

3. On your NewPatient form, you will need Save and Cancel buttons with code
similiar to:

Private sub cmd_Save_Click

me.dirty = false
me.visible = false

end sub

Private sub_cmd_Cancel_Click

me.undo
Docmd.close acForm, "frmNewPatient"

End sub

HTH
Dale
 
H

HeislerKurt

Dale -

This will work great!

Only issue is that the NewPatient command button (actually, an item on
a customized menu) calls a public function with:

=openForm("frmNewPatients")

So, I put the code you suggested into the function (and replaced the
Me. with "Forms!frmPatients"). (I also added an IsLoaded function.).
But for obvious reasons, when I click the Cancen button on
frmNewPatients, I get:

"This action can't be carried out while processing a form or
report event."

.... which points to: DoCmd.Close acForm, "frmNewPatient"

Since I moved the code to a function, how can I stop the code in order
to close frmNewPatient?

Thank you!

###

Public Function openForm(strForm As String)

Dim rs As Object

DoCmd.openForm strForm, , , , , acDialog

If IsLoaded("frmNewPatient") Then
Forms!frmPatients.Requery
'Me.Requery ' This will add the new record to the main form
Set rs = Forms!frmPatients.RecordsetClone
rs.FindFirst "[PtID] = " & Forms("frmNewPatient").txtPtID
If Not rs.NoMatch Then
Forms!frmPatients.Bookmark = rs.Bookmark
rs.Close
Set rs = Nothing
DoCmd.Close acForm, "frmNewPatient"
End If
End If

End Function

###

Public Function IsLoaded(ByVal strFormName As String) As Integer
'Returns a 0 if form is not open or a -1 if Open
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0
Then
If Forms(strFormName).CurrentView <> 0 Then
IsLoaded = True
End If
End If
End Function

###

Kurt,

1. Get rid of the code in the New Patients open event.

2. On the main form, in the code behind your "NewPatient" command button,
put something like:

Private Sub cmdNewPatient_Click

Dim rs as dao.recordset

'I probably don't have the right number of commas here
Docmd.openform "frmNewPatient",,,,,acDialog

'This code wont run until the NewPatient form is hidden or closed

'You will need a function IsLoaded to determine whether the NewPatient
'form is loaded. You can search this forum for the function if you don't
'already have it.
If isloaded("frmNewPatient") then
me.requery 'This will add the new record to the main form
Set rs = me.recordsetclone
rs.FindFirst "[PatientID] = " & Forms("frmNewPatient").txt_Patient_ID
if not rs.nomatch then me.bookmark = rs.bookmark
rs.close
set rs = nothing
docmd.close acform, "frmNewPatient"
endif
End sub

3. On your NewPatient form, you will need Save and Cancel buttons with code
similiar to:

Private sub cmd_Save_Click

me.dirty = false
me.visible = false

end sub

Private sub_cmd_Cancel_Click

me.undo
Docmd.close acForm, "frmNewPatient"

End sub

HTH
Dale

--
Email address is not valid.
Please reply to newsgroup only.



I'd rather not enable/disable the controls as needed, or setting the
Allow Edits, Additions, etc. properties.
I'm doing this mainly for GUI purposes and to maximize screen real
estate on the main form.
I also wasn't clear in my first post.
On the main form, I'm using a lot of calculated text boxes to
concatenate information from several fields about the patient. I'm
doing this mainly for GUI purposes, as it allows to me to show a lot
of basic patient information (name, demographics, etc.) in a small row
across the top of the form (in the Form Header), where it will stay -
not easily edited (but editable just in case) - as the user works
through various subforms below. Putting the *actual* controls in this
same area along the top will take up too much screen real estate.
Hoping this makes sense,
Kurt- Hide quoted text -

- Show quoted text -
 
D

Dale Fye

Kurt,

If your call to the custom function is correct, then the docmd.Close line
is missing an 's' at the end of the form name. It should read:

docmd.close acForm, "frmNewPatients"

Also, the references to the form in the code should all have the same name.
Actually, I think I would create a form variable and set that:

Public Function openForm(strForm As String)

Dim frm as Form
Dim rs As Object

DoCmd.openForm strForm, , , , , acDialog

If IsLoaded(strForm) Then
Set frm = Forms("frmPatients")
frmRequery
Set rs = Frm.RecordsetClone
rs.FindFirst "[PtID] = " & Forms(strForm).txtPtID
If rs.NoMatch Then
msgbox "New patient ID not found!"
Else
frm.bookmark = rs.Bookmark
End If
rs.Close
Set rs = Nothing
DoCmd.Close acForm, strForm
End If

End Function

Hope this does it.
Dale

Dale -

This will work great!

Only issue is that the NewPatient command button (actually, an item on
a customized menu) calls a public function with:

=openForm("frmNewPatients")

So, I put the code you suggested into the function (and replaced the
Me. with "Forms!frmPatients"). (I also added an IsLoaded function.).
But for obvious reasons, when I click the Cancen button on
frmNewPatients, I get:

"This action can't be carried out while processing a form or
report event."

... which points to: DoCmd.Close acForm, "frmNewPatient"

Since I moved the code to a function, how can I stop the code in order
to close frmNewPatient?

Thank you!

###

Public Function openForm(strForm As String)

Dim rs As Object

DoCmd.openForm strForm, , , , , acDialog

If IsLoaded("frmNewPatient") Then
Forms!frmPatients.Requery
'Me.Requery ' This will add the new record to the main form
Set rs = Forms!frmPatients.RecordsetClone
rs.FindFirst "[PtID] = " & Forms("frmNewPatient").txtPtID
If Not rs.NoMatch Then
Forms!frmPatients.Bookmark = rs.Bookmark
rs.Close
Set rs = Nothing
DoCmd.Close acForm, "frmNewPatient"
End If
End If

End Function

###

Public Function IsLoaded(ByVal strFormName As String) As Integer
'Returns a 0 if form is not open or a -1 if Open
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0
Then
If Forms(strFormName).CurrentView <> 0 Then
IsLoaded = True
End If
End If
End Function

###

Kurt,

1. Get rid of the code in the New Patients open event.

2. On the main form, in the code behind your "NewPatient" command
button,
put something like:

Private Sub cmdNewPatient_Click

Dim rs as dao.recordset

'I probably don't have the right number of commas here
Docmd.openform "frmNewPatient",,,,,acDialog

'This code wont run until the NewPatient form is hidden or closed

'You will need a function IsLoaded to determine whether the
NewPatient
'form is loaded. You can search this forum for the function if you
don't
'already have it.
If isloaded("frmNewPatient") then
me.requery 'This will add the new record to the main form
Set rs = me.recordsetclone
rs.FindFirst "[PatientID] = " &
Forms("frmNewPatient").txt_Patient_ID
if not rs.nomatch then me.bookmark = rs.bookmark
rs.close
set rs = nothing
docmd.close acform, "frmNewPatient"
endif
End sub

3. On your NewPatient form, you will need Save and Cancel buttons with
code
similiar to:

Private sub cmd_Save_Click

me.dirty = false
me.visible = false

end sub

Private sub_cmd_Cancel_Click

me.undo
Docmd.close acForm, "frmNewPatient"

End sub

HTH
Dale

--
Email address is not valid.
Please reply to newsgroup only.



I'd rather not enable/disable the controls as needed, or setting the
Allow Edits, Additions, etc. properties.
I'm doing this mainly for GUI purposes and to maximize screen real
estate on the main form.
I also wasn't clear in my first post.
On the main form, I'm using a lot of calculated text boxes to
concatenate information from several fields about the patient. I'm
doing this mainly for GUI purposes, as it allows to me to show a lot
of basic patient information (name, demographics, etc.) in a small row
across the top of the form (in the Form Header), where it will stay -
not easily edited (but editable just in case) - as the user works
through various subforms below. Putting the *actual* controls in this
same area along the top will take up too much screen real estate.
Hoping this makes sense,
Kurt- Hide quoted text -

- Show quoted text -
 
H

HeislerKurt

If your call to the custom function is correct, then the docmd.Close line
is missing an 's' at the end of the form name. It should read:>
docmd.close acForm, "frmNewPatients"

Actually, the form is named frmNewPatient. I just put the code in the
wrong event!

And your code worked great. Thank you for staying with me.

Now I'm trying to handle the "Edit Patient" command button, which
should open frmNewPatients filtered for the value of PtID on
frmPatients. I created a similar function (openFormEdit) for the The
"Edit Patient" button (=openFormEdit("frmNewPatient").

But frmNewPatients opens on a new record. I'm pretty confident the
recordsource syntax is correct; for some reason (obvious to you, I'm
sure), the value of PtID on the frmPatients isn't getting passed into
it.

###

Public Function openFormEdit(strForm As String)

DoCmd.openForm strForm

Forms!frmNewPatient.RecordSource = "SELECT DISTINCTROW
tblPatients.* " & _
"FROM tblPatients " & _
"WHERE ((tblPatients.PtID = [Forms]![frmPatients]!
[PtID]));"

End If

End Function

###

Thank you again for all your help.

Kurt,

If your call to the custom function is correct, then the docmd.Close line
is missing an 's' at the end of the form name. It should read:

docmd.close acForm, "frmNewPatients"

Also, the references to the form in the code should all have the same name.
Actually, I think I would create a form variable and set that:

Public Function openForm(strForm As String)

Dim frm as Form
Dim rs As Object

DoCmd.openForm strForm, , , , , acDialog

If IsLoaded(strForm) Then
Set frm = Forms("frmPatients")
frmRequery
Set rs = Frm.RecordsetClone
rs.FindFirst "[PtID] = " & Forms(strForm).txtPtID
If rs.NoMatch Then
msgbox "New patient ID not found!"
Else
frm.bookmark = rs.Bookmark
End If
rs.Close
Set rs = Nothing
DoCmd.Close acForm, strForm
End If

End Function

Hope this does it.
Dale




This will work great!
Only issue is that the NewPatient command button (actually, an item on
a customized menu) calls a public function with:

So, I put the code you suggested into the function (and replaced the
Me. with "Forms!frmPatients"). (I also added an IsLoaded function.).
But for obvious reasons, when I click the Cancen button on
frmNewPatients, I get:
"This action can't be carried out while processing a form or
report event."
... which points to: DoCmd.Close acForm, "frmNewPatient"
Since I moved the code to a function, how can I stop the code in order
to close frmNewPatient?
Thank you!

Public Function openForm(strForm As String)
Dim rs As Object
DoCmd.openForm strForm, , , , , acDialog
If IsLoaded("frmNewPatient") Then
Forms!frmPatients.Requery
'Me.Requery ' This will add the new record to the main form
Set rs = Forms!frmPatients.RecordsetClone
rs.FindFirst "[PtID] = " & Forms("frmNewPatient").txtPtID
If Not rs.NoMatch Then
Forms!frmPatients.Bookmark = rs.Bookmark
rs.Close
Set rs = Nothing
DoCmd.Close acForm, "frmNewPatient"
End If
End If
End Function

Public Function IsLoaded(ByVal strFormName As String) As Integer
'Returns a 0 if form is not open or a -1 if Open
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0
Then
If Forms(strFormName).CurrentView <> 0 Then
IsLoaded = True
End If
End If
End Function

Kurt,
1. Get rid of the code in the New Patients open event.
2. On the main form, in the code behind your "NewPatient" command
button,
put something like:
Private Sub cmdNewPatient_Click
Dim rs as dao.recordset
'I probably don't have the right number of commas here
Docmd.openform "frmNewPatient",,,,,acDialog
'This code wont run until the NewPatient form is hidden or closed
'You will need a function IsLoaded to determine whether the
NewPatient
'form is loaded. You can search this forum for the function if you
don't
'already have it.
If isloaded("frmNewPatient") then
me.requery 'This will add the new record to the main form
Set rs = me.recordsetclone
rs.FindFirst "[PatientID] = " &
Forms("frmNewPatient").txt_Patient_ID
if not rs.nomatch then me.bookmark = rs.bookmark
rs.close
set rs = nothing
docmd.close acform, "frmNewPatient"
endif
End sub
3. On your NewPatient form, you will need Save and Cancel buttons with
code
similiar to:
Private sub cmd_Save_Click
me.dirty = false
me.visible = false
end sub
Private sub_cmd_Cancel_Click
me.undo
Docmd.close acForm, "frmNewPatient"
End sub
HTH
Dale
--
Email address is not valid.
Please reply to newsgroup only.
:
I'd rather not enable/disable the controls as needed, or setting the
Allow Edits, Additions, etc. properties.
I'm doing this mainly for GUI purposes and to maximize screen real
estate on the main form.
I also wasn't clear in my first post.
On the main form, I'm using a lot of calculated text boxes to
concatenate information from several fields about the patient. I'm
doing this mainly for GUI purposes, as it allows to me to show a lot
of basic patient information (name, demographics, etc.) in a small row
across the top of the form (in the Form Header), where it will stay -
not easily edited (but editable just in case) - as the user works
through various subforms below. Putting the *actual* controls in this
same area along the top will take up too much screen real estate.
Hoping this makes sense,
Kurt- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 
D

Dale Fye

Kurt,

Use the WhereCondition parameter of the OpenForm method. Something like:

Public Function openFormEdit(strForm As String)

Dim strCriteria as string

strCriteria = "[PTID] = " & Forms("frmPatients").[PtID]
DoCmd.openForm strForm,,, strCriteria, acFormEdit

End Function

This should open frmNewPatient to the record corresponding to the current
record in your main form. It does not requery the main form on exit from
the other form. To do that you will have to open it as a dialog and add
code similiar to the previous code.

HTH
Dale

If your call to the custom function is correct, then the docmd.Close
line
is missing an 's' at the end of the form name. It should read:>
docmd.close acForm, "frmNewPatients"

Actually, the form is named frmNewPatient. I just put the code in the
wrong event!

And your code worked great. Thank you for staying with me.

Now I'm trying to handle the "Edit Patient" command button, which
should open frmNewPatients filtered for the value of PtID on
frmPatients. I created a similar function (openFormEdit) for the The
"Edit Patient" button (=openFormEdit("frmNewPatient").

But frmNewPatients opens on a new record. I'm pretty confident the
recordsource syntax is correct; for some reason (obvious to you, I'm
sure), the value of PtID on the frmPatients isn't getting passed into
it.

###

Public Function openFormEdit(strForm As String)

DoCmd.openForm strForm

Forms!frmNewPatient.RecordSource = "SELECT DISTINCTROW
tblPatients.* " & _
"FROM tblPatients " & _
"WHERE ((tblPatients.PtID = [Forms]![frmPatients]!
[PtID]));"

End If

End Function

###

Thank you again for all your help.

Kurt,

If your call to the custom function is correct, then the docmd.Close
line
is missing an 's' at the end of the form name. It should read:

docmd.close acForm, "frmNewPatients"

Also, the references to the form in the code should all have the same
name.
Actually, I think I would create a form variable and set that:

Public Function openForm(strForm As String)

Dim frm as Form
Dim rs As Object

DoCmd.openForm strForm, , , , , acDialog

If IsLoaded(strForm) Then
Set frm = Forms("frmPatients")
frmRequery
Set rs = Frm.RecordsetClone
rs.FindFirst "[PtID] = " & Forms(strForm).txtPtID
If rs.NoMatch Then
msgbox "New patient ID not found!"
Else
frm.bookmark = rs.Bookmark
End If
rs.Close
Set rs = Nothing
DoCmd.Close acForm, strForm
End If

End Function

Hope this does it.
Dale




This will work great!
Only issue is that the NewPatient command button (actually, an item on
a customized menu) calls a public function with:

So, I put the code you suggested into the function (and replaced the
Me. with "Forms!frmPatients"). (I also added an IsLoaded function.).
But for obvious reasons, when I click the Cancen button on
frmNewPatients, I get:
"This action can't be carried out while processing a form or
report event."
... which points to: DoCmd.Close acForm, "frmNewPatient"
Since I moved the code to a function, how can I stop the code in order
to close frmNewPatient?
Thank you!

Public Function openForm(strForm As String)
Dim rs As Object
DoCmd.openForm strForm, , , , , acDialog
If IsLoaded("frmNewPatient") Then
Forms!frmPatients.Requery
'Me.Requery ' This will add the new record to the main form
Set rs = Forms!frmPatients.RecordsetClone
rs.FindFirst "[PtID] = " & Forms("frmNewPatient").txtPtID
If Not rs.NoMatch Then
Forms!frmPatients.Bookmark = rs.Bookmark
rs.Close
Set rs = Nothing
DoCmd.Close acForm, "frmNewPatient"
End If
End If
End Function

Public Function IsLoaded(ByVal strFormName As String) As Integer
'Returns a 0 if form is not open or a -1 if Open
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0
Then
If Forms(strFormName).CurrentView <> 0 Then
IsLoaded = True
End If
End If
End Function

Kurt,
1. Get rid of the code in the New Patients open event.
2. On the main form, in the code behind your "NewPatient" command
button,
put something like:
Private Sub cmdNewPatient_Click
Dim rs as dao.recordset
'I probably don't have the right number of commas here
Docmd.openform "frmNewPatient",,,,,acDialog
'This code wont run until the NewPatient form is hidden or closed
'You will need a function IsLoaded to determine whether the
NewPatient
'form is loaded. You can search this forum for the function if
you
don't
'already have it.
If isloaded("frmNewPatient") then
me.requery 'This will add the new record to the main form
Set rs = me.recordsetclone
rs.FindFirst "[PatientID] = " &
Forms("frmNewPatient").txt_Patient_ID
if not rs.nomatch then me.bookmark = rs.bookmark
rs.close
set rs = nothing
docmd.close acform, "frmNewPatient"
endif
End sub
3. On your NewPatient form, you will need Save and Cancel buttons
with
code
similiar to:
Private sub cmd_Save_Click
me.dirty = false
me.visible = false
Private sub_cmd_Cancel_Click
me.undo
Docmd.close acForm, "frmNewPatient"
:
I'd rather not enable/disable the controls as needed, or setting the
Allow Edits, Additions, etc. properties.
I'm doing this mainly for GUI purposes and to maximize screen real
estate on the main form.
I also wasn't clear in my first post.
On the main form, I'm using a lot of calculated text boxes to
concatenate information from several fields about the patient. I'm
doing this mainly for GUI purposes, as it allows to me to show a lot
of basic patient information (name, demographics, etc.) in a small
row
across the top of the form (in the Form Header), where it will
stay -
not easily edited (but editable just in case) - as the user works
through various subforms below. Putting the *actual* controls in
this
same area along the top will take up too much screen real estate.
Hoping this makes sense,
Kurt- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 
H

HeislerKurt

Once again - works great. Thanks again!

Kurt,

Use the WhereCondition parameter of the OpenForm method. Something like:

Public Function openFormEdit(strForm As String)

Dim strCriteria as string

strCriteria = "[PTID] = " & Forms("frmPatients").[PtID]
DoCmd.openForm strForm,,, strCriteria, acFormEdit

End Function

This should open frmNewPatient to the record corresponding to the current
record in your main form. It does not requery the main form on exit from
the other form. To do that you will have to open it as a dialog and add
code similiar to the previous code.

HTH
Dale




Actually, the form is named frmNewPatient. I just put the code in the
wrong event!
And your code worked great. Thank you for staying with me.
Now I'm trying to handle the "Edit Patient" command button, which
should open frmNewPatients filtered for the value of PtID on
frmPatients. I created a similar function (openFormEdit) for the The
"Edit Patient" button (=openFormEdit("frmNewPatient").
But frmNewPatients opens on a new record. I'm pretty confident the
recordsource syntax is correct; for some reason (obvious to you, I'm
sure), the value of PtID on the frmPatients isn't getting passed into
it.

Public Function openFormEdit(strForm As String)
DoCmd.openForm strForm
Forms!frmNewPatient.RecordSource = "SELECT DISTINCTROW
tblPatients.* " & _
"FROM tblPatients " & _
"WHERE ((tblPatients.PtID = [Forms]![frmPatients]!
[PtID]));"
End Function

Thank you again for all your help.
Kurt,
If your call to the custom function is correct, then the docmd.Close
line
is missing an 's' at the end of the form name. It should read:
docmd.close acForm, "frmNewPatients"
Also, the references to the form in the code should all have the same
name.
Actually, I think I would create a form variable and set that:
Public Function openForm(strForm As String)
Dim frm as Form
Dim rs As Object
DoCmd.openForm strForm, , , , , acDialog
If IsLoaded(strForm) Then
Set frm = Forms("frmPatients")
frmRequery
Set rs = Frm.RecordsetClone
rs.FindFirst "[PtID] = " & Forms(strForm).txtPtID
If rs.NoMatch Then
msgbox "New patient ID not found!"
Else
frm.bookmark = rs.Bookmark
End If
rs.Close
Set rs = Nothing
DoCmd.Close acForm, strForm
End If
End Function
Hope this does it.
Dale

Dale -
This will work great!
Only issue is that the NewPatient command button (actually, an item on
a customized menu) calls a public function with:
=openForm("frmNewPatients")
So, I put the code you suggested into the function (and replaced the
Me. with "Forms!frmPatients"). (I also added an IsLoaded function.).
But for obvious reasons, when I click the Cancen button on
frmNewPatients, I get:
"This action can't be carried out while processing a form or
report event."
... which points to: DoCmd.Close acForm, "frmNewPatient"
Since I moved the code to a function, how can I stop the code in order
to close frmNewPatient?
Thank you!
###
Public Function openForm(strForm As String)
Dim rs As Object
DoCmd.openForm strForm, , , , , acDialog
If IsLoaded("frmNewPatient") Then
Forms!frmPatients.Requery
'Me.Requery ' This will add the new record to the main form
Set rs = Forms!frmPatients.RecordsetClone
rs.FindFirst "[PtID] = " & Forms("frmNewPatient").txtPtID
If Not rs.NoMatch Then
Forms!frmPatients.Bookmark = rs.Bookmark
rs.Close
Set rs = Nothing
DoCmd.Close acForm, "frmNewPatient"
End If
End If
End Function
###
Public Function IsLoaded(ByVal strFormName As String) As Integer
'Returns a 0 if form is not open or a -1 if Open
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0
Then
If Forms(strFormName).CurrentView <> 0 Then
IsLoaded = True
End If
End If
End Function
###
Kurt,
1. Get rid of the code in the New Patients open event.
2. On the main form, in the code behind your "NewPatient" command
button,
put something like:
Private Sub cmdNewPatient_Click
Dim rs as dao.recordset
'I probably don't have the right number of commas here
Docmd.openform "frmNewPatient",,,,,acDialog
'This code wont run until the NewPatient form is hidden or closed
'You will need a function IsLoaded to determine whether the
NewPatient
'form is loaded. You can search this forum for the function if
you
don't
'already have it.
If isloaded("frmNewPatient") then
me.requery 'This will add the new record to the main form
Set rs = me.recordsetclone
rs.FindFirst "[PatientID] = " &
Forms("frmNewPatient").txt_Patient_ID
if not rs.nomatch then me.bookmark = rs.bookmark
rs.close
set rs = nothing
docmd.close acform, "frmNewPatient"
endif
End sub
3. On your NewPatient form, you will need Save and Cancel buttons
with
code
similiar to:
Private sub cmd_Save_Click
me.dirty = false
me.visible = false
end sub
Private sub_cmd_Cancel_Click
me.undo
Docmd.close acForm, "frmNewPatient"
End sub
HTH
Dale
--
Email address is not valid.
Please reply to newsgroup only.
:
I'd rather not enable/disable the controls as needed, or setting the
Allow Edits, Additions, etc. properties.
I'm doing this mainly for GUI purposes and to maximize screen real
estate on the main form.
I also wasn't clear in my first post.
On the main form, I'm using a lot of calculated text boxes to
concatenate information from several fields about the patient. I'm
doing this mainly for GUI purposes, as it allows to me to show a lot
of basic patient information (name, demographics, etc.) in a small
row
across the top of the form (in the Form Header), where it will
stay -
not easily edited (but editable just in case) - as the user works
through various subforms below. Putting the *actual* controls in
this
same area along the top will take up too much screen real estate.
Hoping this makes sense,
Kurt- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 

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