Solved

Open form pass parameter

Posted on 2013-10-22
13
452 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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 …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

630 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