ADD Mode

G

Guest

Could someone please help me with the code I need to add to the below code to
have the fome open in ADD-Mode.

This command button links the forms by "ICNNO" opening the form "f_ProvADD"
It currently opens the from with populated information. I need to have it
open in add mode but still linked.


Private Sub cmdProvADD_Click()
On Error GoTo Err_cmdProvADD_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "f_ProvADD"

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

Exit_cmdProvADD_Click:
Exit Sub

Err_cmdProvADD_Click:
MsgBox Err.Description
Resume Exit_cmdProvADD_Click

End Sub
 
K

Ken Snell \(MVP\)

Add a value to the fifth argument to specify the Add mode:

DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
 
G

Guest

With your suggested code it does not open a linked form. Also, if I change
the "data entry" property to YES on the form I'm opening, it also brakes the
link.

The form I am opening is created from the same table as the main form.
But, it has a subform that is how I established the link to open the correct
form.

Main form is for Patients. Form that opens in this code is for Doctors.
The Patient id="ICNNo". Patients can have multiple Doctors.

So, when I click the command button, I'm trying to add another provider for
that Patient....

How can I maintian this link and still open the form to add another Doctor?
What am I missing?????





How can I maintain the link (display the ICNNo) but be able to add




Ken Snell (MVP) said:
Add a value to the fifth argument to specify the Add mode:

DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd


--

Ken Snell
<MS ACCESS MVP>



Dan @BCBS said:
Could someone please help me with the code I need to add to the below code
to
have the fome open in ADD-Mode.

This command button links the forms by "ICNNO" opening the form
"f_ProvADD"
It currently opens the from with populated information. I need to have it
open in add mode but still linked.


Private Sub cmdProvADD_Click()
On Error GoTo Err_cmdProvADD_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "f_ProvADD"

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

Exit_cmdProvADD_Click:
Exit Sub

Err_cmdProvADD_Click:
MsgBox Err.Description
Resume Exit_cmdProvADD_Click

End Sub
 
G

Guest

Try opening your child form once then use callbacks to sync it with the main
form.

' In a module
Public Function IsOpen(strForm As String) As Boolean
IsOpen = (SysCmd(acSysCmdGetObjectState, acForm, strForm) > 0)
End Function

' In main form
Private f_ProvADD As Form_f_ProvADD

' put this where you want to "open" your child form
If IsOpen("f_ProvADD") And Not f_ProvADD Is Nothing Then
f_ProvADD.FilterDesc = "[ICNNo]=" & "'" & Me![ICNNo] & "'"
f_ProvADD.SetFocus
Else
DoCmd.OpenForm "f_ProvADD", _
DataMode:=acFormAdd, _
WindowMode:=acWindowNormal, _
OpenArgs:="[ICNNo]=" & "'" & Me![ICNNo] & "'"
Set f_ProvADD = Application.Forms("f_ProvADD")
f_ProvADD.SetFocus
End If

' In child form
Property Let FilterDesc(strValue As String)
strFilterDesc = strValue
' put whatever code you need to reinitialize form
' filter or new recordset and whatever
End Property
Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
' Can open a recordset for the form or
me.filter = me.openArgs ' or whatever you want to do here
End If
End Sub

--
Pictou


Dan @BCBS said:
With your suggested code it does not open a linked form. Also, if I change
the "data entry" property to YES on the form I'm opening, it also brakes the
link.

The form I am opening is created from the same table as the main form.
But, it has a subform that is how I established the link to open the correct
form.

Main form is for Patients. Form that opens in this code is for Doctors.
The Patient id="ICNNo". Patients can have multiple Doctors.

So, when I click the command button, I'm trying to add another provider for
that Patient....

How can I maintian this link and still open the form to add another Doctor?
What am I missing?????





How can I maintain the link (display the ICNNo) but be able to add




Ken Snell (MVP) said:
Add a value to the fifth argument to specify the Add mode:

DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd


--

Ken Snell
<MS ACCESS MVP>



Dan @BCBS said:
Could someone please help me with the code I need to add to the below code
to
have the fome open in ADD-Mode.

This command button links the forms by "ICNNO" opening the form
"f_ProvADD"
It currently opens the from with populated information. I need to have it
open in add mode but still linked.


Private Sub cmdProvADD_Click()
On Error GoTo Err_cmdProvADD_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "f_ProvADD"

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

Exit_cmdProvADD_Click:
Exit Sub

Err_cmdProvADD_Click:
MsgBox Err.Description
Resume Exit_cmdProvADD_Click

End Sub
 
K

Ken Snell \(MVP\)

To what value do you set the stLinkCriteria variable before you open that
form? The stLinkCriteria variable should contain the "WHERE" clause (without
WHERE) that is used to filter the form's records to the one you want --
essentially, that variable should be passing a string expression similar to
this (I assume that your first form has a field named ICNNo in the form's
recordset):

stLinkCriteria = "ICNNo=" & Me.ICNNo.Value


Is there any reason why you're not using a form/subform setup, with the
Patients data in the main form and the Doctors linked to that Patient in the
subform?
--

Ken Snell
<MS ACCESS MVP>



Dan @BCBS said:
With your suggested code it does not open a linked form. Also, if I
change
the "data entry" property to YES on the form I'm opening, it also brakes
the
link.

The form I am opening is created from the same table as the main form.
But, it has a subform that is how I established the link to open the
correct
form.

Main form is for Patients. Form that opens in this code is for Doctors.
The Patient id="ICNNo". Patients can have multiple Doctors.

So, when I click the command button, I'm trying to add another provider
for
that Patient....

How can I maintian this link and still open the form to add another
Doctor?
What am I missing?????





How can I maintain the link (display the ICNNo) but be able to add




Ken Snell (MVP) said:
Add a value to the fifth argument to specify the Add mode:

DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd


--

Ken Snell
<MS ACCESS MVP>



Dan @BCBS said:
Could someone please help me with the code I need to add to the below
code
to
have the fome open in ADD-Mode.

This command button links the forms by "ICNNO" opening the form
"f_ProvADD"
It currently opens the from with populated information. I need to have
it
open in add mode but still linked.


Private Sub cmdProvADD_Click()
On Error GoTo Err_cmdProvADD_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "f_ProvADD"

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

Exit_cmdProvADD_Click:
Exit Sub

Err_cmdProvADD_Click:
MsgBox Err.Description
Resume Exit_cmdProvADD_Click

End Sub
 

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

Similar Threads

Add record and update List 5
Type Mismatch 3
Open based on two values 4
Can't Save 2
Write Conflict 6
Criteria when opening form 1
Updating Data 5
If Statements 2

Top