Solved

Open form pass parameter

Posted on 2013-10-22
13
443 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now