Open pop-up form with linked criteria ???

D

Dave Elliott

Main form is named TimeCards with a memo field on it named Job Description
I want the pop-up form named frmJobDescription to open and show the job
description for the record that is open on the main form.
The pop-up form should show only the job description for each TimeCard or
record.
Somehow I need to link the criteria, how???

I tried the below code, but it did not work.
The record source is set the same for both forms.

On Error GoTo Err_Command11_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmJobDescription"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command11_Click:
Exit Sub

Err_Command11_Click:
MsgBox err.Description
Resume Exit_Command11_Click
 
T

Tony Vrolyk

To be clear - you want a pop-up that shows the same data as is currently
displayed in the Description text box on the main form. Also to be clear
your memo field is actually a text box with a control source of a memo
field - there is no such thing as a memo field on a form. It took me a while
to remember that myself.

I would not open the description pop-up using link criteria. That requires
that the pop-up have a recordsource the same as or at close to the same as
the main form. You can then run into write conflicts if data is changed on
the main form and then on the pop-up without first saving the main form. I
would use an unbound form and unbound control and use code to update the
description on the main form.

Create your pop-up form without using the wizard. Leave the form record
source blank. Add the text box with no control source and call it something
like txtDescription. Set the form the Pop-up = yes and Modal = yes.

The in the OnOpen event of the pop-up form set the control to equal the
matching control on the main form:

Private Sub Form_Open(Cancel As Integer)
Me.txtDescription = Forms!MainForm!Description
End Sub

Add a close button with code like the follwing:

Private Sub cmdClose_Click()
Forms!MainForm!Description = Me.txtDescription
DoCmd.Close
End Sub

You can also add a cancel button. Since you didn't actually open the record
there is nothing to do except close the form:

Private Sub cmdCancel_Click()
DoCmd.Close
End Sub

In the end only your main form actually gets dirty from the edit so if you
have any BeforeUpdate or AfterUpdate code on the main form you don't have to
replicate it to the pop-up and you will not get any write conflicts. This
may be a bit rough but should give you an idea of what to do. And there are
other solutions but I have found this pretty reliable.

Another nice thing to do when opening the pop-up is to move the curser to
the end of the text box rather than the default. You could do that with the
following:

Private Sub txtDescription_GotFocus()
Me.txtDescription.SelStart = Len(Me.txtDescription)
End Sub

Hope that helps
Tony Vrolyk
 
D

Dave Elliott

Ok, got it, how can I save the main form record automatically after editing
the pop-up form text without having to use the Pencil or going to next
record or closing?
 
T

Tony Vrolyk

Assuming you are using Access 2000 or later you could do the following:

Private Sub cmdClose_Click()
Forms!MainForm!Description = Me.txtDescription
Forms!MaiunForm.Dirty = False
DoCmd.Close acForm, "PopupForm"
End Sub

Notice I also changed the close command to expressly close the pop-up form.
I use this frequently to make sure I am closing the correct form. If focus
were given to another form during the routine then the close command would
close the one with focus and not one you want to close.

Also you should notice that when referring the fields on a form vs form
properties the exclamations and periods are used differently. There is a
great document at Dev Ashish's site that I use as a reference frequently
http://www.mvps.org/access/forms/frm0031.htm

Tony V
 

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