Solved

Open form pass parameter

Posted on 2013-10-22
13
450 Views
Last Modified: 2013-10-22
Hello, I'm using the following code to open a form and pass a value from the existing form.
When my code runs I get the following error:

The openform dialog was canceled


What am I doing wrong?



Private Sub Email_DMR_Click()

 On Error GoTo Err_btnEmailReportNew_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Email DMR"
     DoCmd.OpenForm stDocName, acNormal, , , , , SUPPLIER.Value

Exit_btnEmailReportNew_Click:
    Exit Sub

Err_btnEmailReportNew_Click:
    MsgBox Err.Description
    Resume Exit_btnEmailReportNew_Click
    
   
End Sub

Open in new window

0
Comment
Question by:gogetsome
  • 6
  • 4
  • 3
13 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 250 total points
ID: 39591669
The error is probably occurring in the open event of your "Email DMR" form.

What code is in that form's Open Event?
0
 

Author Comment

by:gogetsome
ID: 39591702
This is the only code on that form. The "Email DMR" form does have Modal set to yes if that is the problem.

Private Sub Cancel_Click()

DoCmd.Close 'Close Form

End Sub

Private Sub Form_Load()

 If Not IsNull(Me.OpenArgs) Then
        txt_Supplier.Value = Me.OpenArgs
         
    End If

End Sub

Open in new window

0
 
LVL 61

Expert Comment

by:mbizup
ID: 39591736
Can you post a sample copy of your database?
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:gogetsome
ID: 39591746
I wish I could but I don't own it and have signed an NDA.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39591814
<I wish I could but I don't own it and have signed an NDA. >
...as was stated, a "sample" copy of the db was requested...

So we just need a db that exhibits this problem...
...At the very least, tell us what this code is supposed to be doing here, and what the open code on the second form is supposed to be doing...

As mbizup stated, this seems like an issue with the second form, so without any details on the code, it is difficult to say what the exact problem is...

The code to do what you are asking is fairly basic, ...if you are truing to "filter" the second form with this code , then make sure the correct value is being passed...

Do this first and see what it returns:
    msgbox SUPPLIER.Value

If you are trying to open the the second form with this passed value as the "Filter"  then use code like this:
    DoCmd.OpenForm stDocName, acNormal, , "Supplier=" & SUPPLIER.Value
...or this if "Supplier" is textual
    DoCmd.OpenForm stDocName, acNormal, , "Supplier=" & "'" & SUPPLIER.Value & "'"

Finally (just to be sure), make fore you spelled the second form correctly
"Email DMR"
"Email_DMR"
"frmEmail DMR"
 'frm_Email DMR"
0
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 250 total points
ID: 39591848
Ooopps
I see the code ...

If Not IsNull(Me.OpenArgs) Then
        txt_Supplier.Value = Me.OpenArgs
         
    End If

So make sure the datatype of the Open arg is the same as the datatype defined in the table for the Supplier field.


Also, your code can  fail if the controlsource for the Supplier control on the second form is
    =Supplier
So make sure the control-source is just:
    Supplier

Finally try that code on the Open event of the form (not the load event)...
The open event can at least be cancelled in case of an error...

JeffCoachman
0
 

Author Comment

by:gogetsome
ID: 39591959
Thank you both! I'm working on your suggestions and will update soon. Sorry about being short on explanation.
0
 

Author Closing Comment

by:gogetsome
ID: 39592889
Thank you both for your assistance. It was very helpful!
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39592947
so what was the post that helped?
0
 

Author Comment

by:gogetsome
ID: 39592971
mbizup's post led me to look at the form I was opening.

Your post made me ensure the value I was passing was correct.

In all I found a mistake in the value I was passing and that the form I was passing too was already open so I could not open it again.

So I thing both posts were helpful.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39592978
--->  the form I was passing too was already open ...

Depending on your application, this might be a worthwhile check:

If CurrentProject.AllForms("YourFormName"). IsLoaded = True
       '  Do stuff here if the form is loaded
Else
        ' Do other stuff here if the form is not loaded
End If

Open in new window

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39593044
Glad we could help...
;-)
0
 

Author Comment

by:gogetsome
ID: 39593057
Thank you so much. I  normally work with .Net but having fun with Access this month. It is different in so many ways! I'm really enjoying it so far. I'm sure I will be back with more questions.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question