473,386 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Open a form passing a value

ddtpmyra
333 100+
I have two forms.
1st form has worksheet grid list menu

what I wanted to do is whenever my user click the record number from the worksheet grid list (1st form) it will open my detail form with equivalent record number that was selected on the first form.

how to do that?
May 31 '11 #1

✓ answered by NeoPa

There's only one argument, but it can be a string with various values embedded within it. Assuming MR is a numeric you could use :
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.OpenForm(FormName:="frm_MRHolder", _
  2.                     OpenArgs:=Me.MR & "," & Format(Me.Date, "Short Date"))
In the code to handle receiving the data you would want something like :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     Dim ID_Arg As Long
  3.     Dim Date_Arg As Date
  4.     Dim strArgs As String
  5.  
  6.     ' load the openarg into the local variable id_arg
  7.  
  8.     strArgs = Nz(Me.OpenArgs, "")
  9.     ID_Arg = Val(Split(strArgs, ",")(0))
  10.     Date_Arg = CDate(Split(strArgs, ",")(1))
  11.  
  12.     ' check to see if the id_arg is not zero.  
  13.  
  14.     If ID_Arg <> 0 Then
  15.         Me.Filter = "([MR]=" & ID_Arg & ") AND " & _
  16.                     "([Date]=#" & Format(Date_Arg, 'm/d/yyyy') & "#)"
  17.         Me.FilterOn = True
  18.     End If
  19. End Sub
Remember though, you can easily apply a filter from the calling code anyway. Another parameter is called WhereCondition.

5 7326
NeoPa
32,556 Expert Mod 16PB
Use the OpenArgs parameter of the call to DoCmd.OpenForm().
May 31 '11 #2
ddtpmyra
333 100+
Here what I do...

Form A Code (event: double click)
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "frm_B", acNormal, , , , , Me.MR
Form B Code (event: on open)
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. Dim ID_Arg As Long
  3.  
  4. ' load the openarg into the local variable id_arg
  5.  
  6. ID_Arg = Nz(Form_frm_B.OpenArgs, 0)
  7.  
  8. ' check to see if the id_arg is not zero.  
  9.  
  10. If ID_Arg <> 0 Then
  11.  
  12.     Me.Filter = "MR=" & ID_Arg
  13.     Me.FilterOn = True
  14.  
  15. End If
  16. End Sub
  17.  
Expand|Select|Wrap|Line Numbers
  1. Run-time error: 2001
  2. You cancelled the previous operation
Need help to debug.
Jun 1 '11 #3
NeoPa
32,556 Expert Mod 16PB
I think we can probably help there. First see Debugging in VBA.

Now, you may want to start by changing the .OpenArgs object reference in line #6 to :
Expand|Select|Wrap|Line Numbers
  1. ID_Arg = Nz(Me.OpenArgs, 0)
Lastly, to allow anyone to help, you need to describe what happens and where the code is highlighted when you click the debug option. We need to know which line the problem occurred on.
Jun 2 '11 #4
ddtpmyra
333 100+
Can I have more than one OpenArg? Below is my current code during the event on double click.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "frm_MRHolder", OpenArgs:=Me.MR
  2.  
I wanted to have MR and Date
Jun 20 '11 #5
NeoPa
32,556 Expert Mod 16PB
There's only one argument, but it can be a string with various values embedded within it. Assuming MR is a numeric you could use :
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.OpenForm(FormName:="frm_MRHolder", _
  2.                     OpenArgs:=Me.MR & "," & Format(Me.Date, "Short Date"))
In the code to handle receiving the data you would want something like :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     Dim ID_Arg As Long
  3.     Dim Date_Arg As Date
  4.     Dim strArgs As String
  5.  
  6.     ' load the openarg into the local variable id_arg
  7.  
  8.     strArgs = Nz(Me.OpenArgs, "")
  9.     ID_Arg = Val(Split(strArgs, ",")(0))
  10.     Date_Arg = CDate(Split(strArgs, ",")(1))
  11.  
  12.     ' check to see if the id_arg is not zero.  
  13.  
  14.     If ID_Arg <> 0 Then
  15.         Me.Filter = "([MR]=" & ID_Arg & ") AND " & _
  16.                     "([Date]=#" & Format(Date_Arg, 'm/d/yyyy') & "#)"
  17.         Me.FilterOn = True
  18.     End If
  19. End Sub
Remember though, you can easily apply a filter from the calling code anyway. Another parameter is called WhereCondition.
Jun 20 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: P | last post by:
Hi, Access 2002. I am trying to use the PrintOut function to print the current record of the current open form in landscape format to the default Windows printer. Any suggestion on how to set...
7
by: sara | last post by:
I have a form where the user selects an item from a list box, and then works on that item. The user chooses an AD, then opens a form to assign departments to the ad. The top of the Depts form has...
5
by: Stuart | last post by:
Hi all, Iv'e got a page that has a mass amount of input fields, all of which require a decimal figure. To make it easier when it comes to inputting data, I'm trying to setup + and - links that...
2
by: sangram | last post by:
Passing value from parent to child window created by Pop up
6
by: Franck | last post by:
I know in vb6 it was super easy to pass parameter or either read example the textbox1.text on the already open form form2 like all object were as public. but is there a way to do something that...
4
idsanjeev
by: idsanjeev | last post by:
SIR I AM PASSING VALUE FROM ONE FORM TO ANOTHER FORM THROUGH COOKIES BUT IS CAN ONLY TRANSFER LAST VALUE HOW CAN PASS VALUE AFTER CLICKIN ON LINK I AM USING THE CODE IS FOR LINK <td><a...
3
by: vidhyapriya | last post by:
Hi all I am developing windows application using vb.net.I want to pass values to open form.I am opening only one form when user click the buttons several times.Useing delegate i am passing...
0
by: vidhyapriya | last post by:
Hi all, I am using two forms.From form1 button click i am opening form2,and i am passing values to form2 using delegate.when i click the button again form2 shouldn't open again but values...
16
by: littlegreen | last post by:
Hi all, I would like to know how to assign and get the form value when I using it in a loop. I cannot get all the input that I inserted in 'Desc' part and it is from this site. May I know to get...
8
sickenhoofer
by: sickenhoofer | last post by:
I have a form, 'frmProviderMain' with a macro which opens another form, frmEnrollmentProcessing.The macro is located on a tab on 'frmProviderMain.' I would like one of the controls/fields on the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.