Solved

Open form pass parameter

Posted on 2013-10-22
13
451 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 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

752 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