Trouble passing value to new form

  • Thread starter cableguy47905 via AccessMonster.com
  • Start date
C

cableguy47905 via AccessMonster.com

I am having the hardest time trying to pass a single value from one form to
another form that I am opening with a cmd button.

I have a main form that is already populated and I am trying to open a new
form that will have one value passed to it from the original form. This new
form will be data entry and the value that I am passing to it will be one
half of the primary key for the query that the form is based on. The other
half would be entered in once the form is opened.

I have tried every example that is on this discussion board, and I still have
no luck. I have tried it in the Where statement, but just get it filtered,
but still no values showing up. I guess ultimately I do want it filtered on
the CompanyID, that way the rest of the fields would fill in also, but I
still just get it to open to a blank form.

Here is my code. I don't get errors, I also don't get anything for that
control either. CompanyID is numeric.

Can anyone help?

Thanks in advance,
Lee

Private Sub cmdAddContract_Click()
On Error GoTo Err_cmdAddContract_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FRM_CompanyAddContracts"
stLinkCriteria = "txtCompanyID.defaultvalue =" & Me.txtCompanyID

DoCmd.OpenForm stDocName, , , , acFormAdd, acWindowNormal, stLinkCriteria
Exit_cmdAddContract_Click:
Exit Sub

Err_cmdAddContract_Click:
MsgBox Err.Description
Resume Exit_cmdAddContract_Click

End Sub
 
C

Carl Rapson

cableguy47905 via AccessMonster.com said:
I am having the hardest time trying to pass a single value from one form to
another form that I am opening with a cmd button.

I have a main form that is already populated and I am trying to open a new
form that will have one value passed to it from the original form. This
new
form will be data entry and the value that I am passing to it will be one
half of the primary key for the query that the form is based on. The
other
half would be entered in once the form is opened.

I have tried every example that is on this discussion board, and I still
have
no luck. I have tried it in the Where statement, but just get it
filtered,
but still no values showing up. I guess ultimately I do want it filtered
on
the CompanyID, that way the rest of the fields would fill in also, but I
still just get it to open to a blank form.

Here is my code. I don't get errors, I also don't get anything for that
control either. CompanyID is numeric.

Can anyone help?

Thanks in advance,
Lee

Private Sub cmdAddContract_Click()
On Error GoTo Err_cmdAddContract_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FRM_CompanyAddContracts"
stLinkCriteria = "txtCompanyID.defaultvalue =" & Me.txtCompanyID

DoCmd.OpenForm stDocName, , , , acFormAdd, acWindowNormal,
stLinkCriteria
Exit_cmdAddContract_Click:
Exit Sub

Err_cmdAddContract_Click:
MsgBox Err.Description
Resume Exit_cmdAddContract_Click

End Sub

The code you posted is passing your criteria in the OpenArgs parameter, not
the Filter or Where parameter. To use that, you'll have to do something with
it in the form's Open or Load event. Here's something you could try: in the
Load event, modify the form's Record Source property to incorporate the
passed WHERE clause:

Me.RecordSource = Me.RecordSource & " WHERE " & Me.OpenArgs

Of course, that assumes the form's Record Source doesn't already have a
WHERE clause on it.

Carl Rapson
 
C

cableguy47905 via AccessMonster.com

Thanks for the quick response. This group is always so helpful. I was able
to use the Northwind DB as an example with one of their forms. After using
the same format, I was able to get mine to work. I did end up using the the
Where clause and filtered my form. My problem was that the form I was
opening was in Data Entry mode therefore it was always blank.
The simplest things can really cause a lot of trouble.

Thanks again for the suggestion.
Lee

Carl said:
I am having the hardest time trying to pass a single value from one form to
another form that I am opening with a cmd button.
[quoted text clipped - 43 lines]

The code you posted is passing your criteria in the OpenArgs parameter, not
the Filter or Where parameter. To use that, you'll have to do something with
it in the form's Open or Load event. Here's something you could try: in the
Load event, modify the form's Record Source property to incorporate the
passed WHERE clause:

Me.RecordSource = Me.RecordSource & " WHERE " & Me.OpenArgs

Of course, that assumes the form's Record Source doesn't already have a
WHERE clause on it.

Carl Rapson
 

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