Open Args and Pop-up form

  • Thread starter Thread starter Cameron Piper
  • Start date Start date
C

Cameron Piper

For a general layout of my database as it pertains to
this question, see database layout below.

I am having trouble with a popup form that is not opening
to the right Record when opened. (form open code below)
If a client already has a phone number in the databse,
there is no problem. The form opens to that client's
phone number(s) and I am able to add, edit, and delete
them with no problems.

The problem that I am having is when I open a client
without a phone number, it will open to a blank form and
all seems well, but if I add a phone number in the
subform, it will assign it a clientID number of zero.

In the reading that I did on google today, I think that I
should be using the openargs command in the form open
event. Will someone please help me make sense of this.
The text that I tried to used in the open form event was:

Private Sub Form_Open(Cancel As Integer)

Dim strClientID As String
strClientID = Forms!frmClient.OpenArgs

End Sub

But it only returned an error for me. Please Help

Cameron Piper
(e-mail address removed)



Code to Open Form:

Private Sub Command200_Click()
On Error GoTo Err_Command200_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "fsubPhone"

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

Exit_Command200_Click:
Exit Sub

Err_Command200_Click:
MsgBox Err.Description
Resume Exit_Command200_Click

End Sub

Database Layout:

I am working on an access 2002 database on a microsoft
Office and Windows XP based machine.

There are two tables in my question:

1. tblPhones
PhoneID: Primary Key, Autonumber
ClientID: Linked to Primary Key in tblClient
Other Phone Number Fields (areacode, extension, notes,
etc.)

2. tblClient
ClientID: Primary Key, Autonumber
Other Client Fields (namefirst, namelast, occupation,
etc.)

There are two three forms in my question:

1. frmClient: Used to enter all sorts of information
about a client
Record Source: tblClient

2. fsubPhone: Is a popup form opened by a command button
on frmClient. It is simply a hosting form for a few misc
phone command buttons and a subform.

3. fsubPhoneContinuous: Is a subform nested in frmPhone.
Is a continuous view form used to add the actual phone
numbers themselves.
 
Sorry, misunderstand your 1st thread about this. Try to fix it now.

The 'OpenArgs' is an argument in the Docmd.OpenForm and also property of Form. So, your code will look like this:
Private Sub Command200_Click()
On Error GoTo Err_Command200_Click
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "fsubPhone"
stLinkCriteria = "[ClientID]=" & Me![ClientID]
'DoCmd.OpenForm stDocName, , , stLinkCriteria 'old code
DoCmd.OpenForm stDocName, , , stLinkCriteria,,,ClientID 'new code

If you open fsubPhone this way, now you can access the 'OpenArgs' property:
Private Sub Form_Open(Cancel As Integer)
Dim strClientID As String
strClientID = me.openargs
End Sub

Beware, though, for NULL value.

HTH

----- Cameron Piper wrote: -----

For a general layout of my database as it pertains to
this question, see database layout below.

I am having trouble with a popup form that is not opening
to the right Record when opened. (form open code below)
If a client already has a phone number in the databse,
there is no problem. The form opens to that client's
phone number(s) and I am able to add, edit, and delete
them with no problems.

The problem that I am having is when I open a client
without a phone number, it will open to a blank form and
all seems well, but if I add a phone number in the
subform, it will assign it a clientID number of zero.

In the reading that I did on google today, I think that I
should be using the openargs command in the form open
event. Will someone please help me make sense of this.
The text that I tried to used in the open form event was:

Private Sub Form_Open(Cancel As Integer)

Dim strClientID As String
strClientID = Forms!frmClient.OpenArgs

End Sub

But it only returned an error for me. Please Help

Cameron Piper
(e-mail address removed)



Code to Open Form:

Private Sub Command200_Click()
On Error GoTo Err_Command200_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "fsubPhone"

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

Exit_Command200_Click:
Exit Sub

Err_Command200_Click:
MsgBox Err.Description
Resume Exit_Command200_Click

End Sub

Database Layout:

I am working on an access 2002 database on a microsoft
Office and Windows XP based machine.

There are two tables in my question:

1. tblPhones
PhoneID: Primary Key, Autonumber
ClientID: Linked to Primary Key in tblClient
Other Phone Number Fields (areacode, extension, notes,
etc.)

2. tblClient
ClientID: Primary Key, Autonumber
Other Client Fields (namefirst, namelast, occupation,
etc.)

There are two three forms in my question:

1. frmClient: Used to enter all sorts of information
about a client
Record Source: tblClient

2. fsubPhone: Is a popup form opened by a command button
on frmClient. It is simply a hosting form for a few misc
phone command buttons and a subform.

3. fsubPhoneContinuous: Is a subform nested in frmPhone.
Is a continuous view form used to add the actual phone
numbers themselves.
 
Trias,

Thank you so much for your quick reply. I appreciate
greatly all the help that you have been willing to give
me. Unfortunately, after changin all of the code, I am
still having the same problem. Is there something else
that I am overlooking. This seems like such a simple
task. All I want to do is open the form and enter some
phone numbers but do it for the the same person as the
form I was just on. Any other assistance would be
appreciated.

Cameron Piper
-----Original Message-----
Sorry, misunderstand your 1st thread about this. Try to fix it now.

The 'OpenArgs' is an argument in the Docmd.OpenForm and
also property of Form. So, your code will look like this:
Private Sub Command200_Click()
On Error GoTo Err_Command200_Click
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "fsubPhone"
stLinkCriteria = "[ClientID]=" & Me![ClientID]
'DoCmd.OpenForm stDocName, , , stLinkCriteria 'old code
DoCmd.OpenForm stDocName, , ,
stLinkCriteria,,,ClientID 'new code
If you open fsubPhone this way, now you can access the 'OpenArgs' property:
Private Sub Form_Open(Cancel As Integer)
Dim strClientID As String
strClientID = me.openargs
End Sub

Beware, though, for NULL value.

HTH

----- Cameron Piper wrote: -----

For a general layout of my database as it pertains to
this question, see database layout below.

I am having trouble with a popup form that is not opening
to the right Record when opened. (form open code below)
If a client already has a phone number in the databse,
there is no problem. The form opens to that client's
phone number(s) and I am able to add, edit, and delete
them with no problems.

The problem that I am having is when I open a client
without a phone number, it will open to a blank form and
all seems well, but if I add a phone number in the
subform, it will assign it a clientID number of zero.

In the reading that I did on google today, I think that I
should be using the openargs command in the form open
event. Will someone please help me make sense of this.
The text that I tried to used in the open form event was:

Private Sub Form_Open(Cancel As Integer)

Dim strClientID As String
strClientID = Forms!frmClient.OpenArgs

End Sub

But it only returned an error for me. Please Help

Cameron Piper
(e-mail address removed)



Code to Open Form:

Private Sub Command200_Click()
On Error GoTo Err_Command200_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "fsubPhone"

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

Exit_Command200_Click:
Exit Sub

Err_Command200_Click:
MsgBox Err.Description
Resume Exit_Command200_Click

End Sub

Database Layout:

I am working on an access 2002 database on a microsoft
Office and Windows XP based machine.

There are two tables in my question:

1. tblPhones
PhoneID: Primary Key, Autonumber
ClientID: Linked to Primary Key in tblClient
Other Phone Number Fields (areacode, extension, notes,
etc.)

2. tblClient
ClientID: Primary Key, Autonumber
Other Client Fields (namefirst, namelast, occupation,
etc.)

There are two three forms in my question:

1. frmClient: Used to enter all sorts of information
about a client
Record Source: tblClient

2. fsubPhone: Is a popup form opened by a command button
on frmClient. It is simply a hosting form for a few misc
phone command buttons and a subform.

3. fsubPhoneContinuous: Is a subform nested in frmPhone.
Is a continuous view form used to add the actual phone
numbers themselves.

.
 
Can i send you my test db?. if you want just send your email to (e-mail address removed)
 
Back
Top