Referring form

  • Thread starter Thread starter Scott
  • Start date Start date
S

Scott

Hi all,
I'll ask a question first, then give the explanation of what I'm
trying to do if that's not enough info, and then ask the question again.

Is there a way to check the 'referring' form that called the 'OpenForm'
command?

I have a problem where I have one form (Lets call it 'frm_data_entry') which
is opened from two other forms. This first of these forms is basically a
Main menu, and when I have the user click a button it opens the data entry
form, makes it fill the screen, and goes to a new record for them to start
inputting data. I do this simply with the following:

Private Sub Form_Open(Cancel As Integer)

DoCmd.Maximize
DoCmd.GoToRecord , , acNewRec

End Sub

My problem is, I have another 'Search' form which runs some filters for
searching, and lists limited information of appropriate records, which the
user can then double-click on to open the 'frm_data_entry' to see the all of
the information for that record. Trouble is, when I use the following code
on the 'search' form:

Private Sub goto_Click()
On Error GoTo Err_goto_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frm_data_entry"

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

Exit_goto_Click:
Exit Sub

Err_goto_Click:
MsgBox Err.Description
Resume Exit_goto_Click

End Sub

- it opens the 'frm_data_entry' form at the apprpriate entry, and then runs
the
DoCmd.GoToRecord , , acNewRec
in the 'Form Open' and goes to the blank record.

Is there a way to check the 'referring' form that called the 'OpenForm'
command, and then use an If statement to decide whether or not the
'acNewRec' command should be used?

Any help would be greatly appreciated
Thanks in advance
Scott Palmer
 
Hi Scott,
A technique I used once was to pass the referring form name in as the
OpenArgs
parameter in the call DoCmd.OpenForm. Then in the form that you are opening
you can call Me.OpenArgs which will give you what was passed into the form.

E.g
DoCmd.OpenForm "frmToOpen", , , , , , "frmReferringForm"
Then in the Load event of the frmToOpen if you call Me.OpenArgs
it will give the value "frmReferringForm". Consider using a constant
at the top of each form module for the current referring form name.

HTH
 
I've figured out a way to solve my problem - I declared a Public string
'stCall_Form' and I set it to a value - eg. "Main Form" in the code just
before the docmd.openform section. Then on the 'frm_data_entry' form, I test
the public string in an If statement to decide whether or not I use the
'acNewRec' command.

I don't know if this is the 'proper' way to do this, but it works. If anyone
can suggest a reason/other way I should do this, it would be appreciated.

Thanks!
 
Scott said:
Hi all,
I'll ask a question first, then give the explanation of what I'm
trying to do if that's not enough info, and then ask the question again.

Is there a way to check the 'referring' form that called the 'OpenForm'
command?

I have a problem where I have one form (Lets call it 'frm_data_entry') which
is opened from two other forms. This first of these forms is basically a
Main menu, and when I have the user click a button it opens the data entry
form, makes it fill the screen, and goes to a new record for them to start
inputting data. I do this simply with the following:

Private Sub Form_Open(Cancel As Integer)

DoCmd.Maximize
DoCmd.GoToRecord , , acNewRec

End Sub

My problem is, I have another 'Search' form which runs some filters for
searching, and lists limited information of appropriate records, which the
user can then double-click on to open the 'frm_data_entry' to see the all of
the information for that record. Trouble is, when I use the following code
on the 'search' form:

Private Sub goto_Click()
On Error GoTo Err_goto_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frm_data_entry"

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

Exit_goto_Click:
Exit Sub

Err_goto_Click:
MsgBox Err.Description
Resume Exit_goto_Click

End Sub

- it opens the 'frm_data_entry' form at the apprpriate entry, and then runs
the
DoCmd.GoToRecord , , acNewRec
in the 'Form Open' and goes to the blank record.

Is there a way to check the 'referring' form that called the 'OpenForm'
command, and then use an If statement to decide whether or not the
'acNewRec' command should be used?

Any help would be greatly appreciated
Thanks in advance
Scott Palmer
 
In the menu form use the following code instead of the form open code:

DoCmd.OpenForm "'frm_data_entry", , , , acFormAdd
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access

Scott said:
Hi all,
I'll ask a question first, then give the explanation of what I'm
trying to do if that's not enough info, and then ask the question again.

Is there a way to check the 'referring' form that called the 'OpenForm'
command?

I have a problem where I have one form (Lets call it 'frm_data_entry') which
is opened from two other forms. This first of these forms is basically a
Main menu, and when I have the user click a button it opens the data entry
form, makes it fill the screen, and goes to a new record for them to start
inputting data. I do this simply with the following:

Private Sub Form_Open(Cancel As Integer)

DoCmd.Maximize
DoCmd.GoToRecord , , acNewRec

End Sub

My problem is, I have another 'Search' form which runs some filters for
searching, and lists limited information of appropriate records, which the
user can then double-click on to open the 'frm_data_entry' to see the all of
the information for that record. Trouble is, when I use the following code
on the 'search' form:

Private Sub goto_Click()
On Error GoTo Err_goto_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frm_data_entry"

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

Exit_goto_Click:
Exit Sub

Err_goto_Click:
MsgBox Err.Description
Resume Exit_goto_Click

End Sub

- it opens the 'frm_data_entry' form at the apprpriate entry, and then runs
the
DoCmd.GoToRecord , , acNewRec
in the 'Form Open' and goes to the blank record.

Is there a way to check the 'referring' form that called the 'OpenForm'
command, and then use an If statement to decide whether or not the
'acNewRec' command should be used?

Any help would be greatly appreciated
Thanks in advance
Scott Palmer
 
yes, you can always pick up the name of the calling form with:

Screen.ActiveForm.Name


In fact, the above even works as late as the on-load event.

Often, for code simplicity, I define a form level module var like:

Option Explicit

dim frmPrev as form


Then, in the forms on-load event, I go

set frmPrev = Screen.ActiveForm

Now, anywhere in the forms code I can reference fields, code, etc.

msgbox "last name = " & frmPrev!LastName

Or even run code:

frmPrev.MyRefresh
 
Back
Top