Help needed for DoCmd.OpenForm!

RonnieODIN

Registered User.
Local time
Tomorrow, 00:53
Joined
Jun 15, 2012
Messages
46
Hi all,

I am very new to Access and having trouble regarding some code in my DB.

I am trying to open a certain record on a form when clicking a button. As I understand the help function I should be able to use the follosing code - at least that is what I have:

Private Sub cmdRetKomponent_Click()
Dim strKomponentID As String
Select Case KtlFane45
Case 0
strKomponentID = Forms![frmInfoMaskiner]!UnderordnetObjekt76![KomponentID]
DoCmd.OpenForm "frmKompPLC", , , "KomponentID=" & strKomponentID, , acDialog

Anyone having an idea of what I am missing?

For info the form I need to open is frmKompPLC as dialog. I need to sort the records by KomponentID which must be equal to the KomponentID on the subform UnderordnetObjekt76 on the main form frmInfoMaskiner.

What I am getting is the attached pictures for using and leaving out the WHERE-condition for filtered and unfiltered respectively.

It seems like that my old posts are in fact filtered but I am shown a new post anyway.
 

Attachments

  • Unfiltered.jpg
    Unfiltered.jpg
    41.1 KB · Views: 115
  • Filtered.jpg
    Filtered.jpg
    44.3 KB · Views: 112
Code:
DoCmd.OpenForm "frmKompPLC", , , "KomponentID=" & strKomponentID, , acDialog

Two points:

1) Check the order of args being passed to OpenForm. It looks like you mean to pass the ID as the OpenArgs. and that should be in the 7th place.

"DoCmd.OpenForm Method"
http://msdn.microsoft.com/en-us/library/bb238021(v=office.12).aspx

2) OpenArgs passes the value only, not the declaration of a variable as well.

The receiving Form obtains the OpenArgs value via calling Me.OpenArgs.

So did you mean to pass that entire string as the OpenArgs value, or only the value of the strKomponentID variable? The receiving form knows how to interpret that declaration string?
 
I want to open the record for which the ID matches the ID in the subform i.e. I need the value of strKomponentID.

I am not quet sure of whether the opened form knows how to handle the value. How do I check for that?
 
The place where you have acDialog (= 3) should either be acFormAdd (=0), acFormEdit (=1) or acFormReadOnly (=2).
Why you end up in append mode :confused:, should be readonly & edit (= 2+1 = 3):D

And mdlueck is right.
Check the order of the openform arguments.
 
Peter,

As I see it, the position of acDialog is where it is supposed to be: WindowMode. Otherwise I assume that the program would not be running?

But again, where am I to check/put the arguments in the form I am opening?
 
@Ronnie,
strKomponentID = Forms![frmInfoMaskiner]!UnderordnetObjekt76![KomponentID]
should be
strKomponentID = Forms![frmInfoMaskiner]!UnderordnetObjekt76.Form![KomponentID]
 
I am not quet sure of whether the opened form knows how to handle the value. How do I check for that?

Oh....

The form being opened needs code to process the OpenArgs it is being passed. Otherwise you might as well be talking to the wall.

OpenArgs passes into the form being opened a string.

The form receives that string via making a call to Me.OpenArgs and then doing what it should do with whatever string it was passed. Perhaps place this code in the Form_Load event so that the Form acts upon the data as it is first loading.
 
Last edited:
Michael, you seem focused on OpenArgs, but Ronnie has the correct position for a wherecondition, and the correct syntax, presuming the field is numeric. Ronnie, set a breakpoint and make sure the value you expect is in the variable.
 
but Ronnie has the correct position for a wherecondition

From the text it appeared the OP was expecting OpenArgs to do the transportation. Thank you for the clarification.
 
I just realized that I had a macro for the OnOpen event. Removing this solved my problem using the following code:

DoCmd.OpenForm "frmRetKomp", , , "KomponentID=[Forms]![frmInfoMaskiner]![UnderordnetObjekt76]![KomponentID]", , acDialog

I apologize for my confusion and the time you have all spent.
 

Users who are viewing this thread

Back
Top Bottom