Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Open form pass parameter

Posted on 2013-10-22
13
Medium Priority
?
453 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
13 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 1000 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
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 

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 1000 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

670 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