473,503 Members | 5,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to pass a record index to a function that opens a form for that index?

sueb
379 Contributor
I have a function that opens instances of a form when called from the switchboard. However, now I want to open a specific record, but I don't know how to pass/receive the record index.

The structure of my database is such that I have a master table (patients) and a child table (procedure requests), and the index I want is available from the master table's form, on which there is a button that can provide the desired index. (It actually currently does that, but without using the form collection object, which is new.)

Here's the form-opening function (there is an associated collection, and appropriate form-closing functions):

Expand|Select|Wrap|Line Numbers
  1. Function OpenAnIURClient()
  2.     'Purpose:   Open an independent instance of form frmClient.
  3.     Dim frm As Form
  4.  
  5.     'Open a new instance, show it, and set a caption.
  6.     Set frm = New Form_Sorted_by_IUR
  7.     frm.Visible = True
  8.     frm.Caption = frm.Hwnd & ", opened " & Now()
  9.  
  10.     'Append it to our collection.
  11.     clnIURClient.Add Item:=frm, Key:=CStr(frm.Hwnd)
  12.  
  13.     Set frm = Nothing
  14. End Function
  15.  
and here is the button's code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Open_IUR_Subform_Click()
  2. On Error GoTo Err_Open_IUR_Subform_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stMainForm As String
  6.     Dim stLinkCriteria As String
  7.  
  8.     stMainForm = "Patient_IUR_Overview"
  9.     stSubForm = "IURs Abbreviated: subform"
  10.     stDocName = "IURs: subform"
  11.     'stDocName = "Sorted_by_IUR"
  12.  
  13.     DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  14.  
  15.     stLinkCriteria = "[IURs.IUR Index]=" & Me![IUR Index]
  16.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  17.     'OpenAnIURClient ' Need to be able to pass the link criteria to this
  18.  
  19. Exit_Open_IUR_Subform_Click:
  20.     Exit Sub
  21.  
  22. Err_Open_IUR_Subform_Click:
  23.     MsgBox Err.Description
  24.     Resume Exit_Open_IUR_Subform_Click
  25.  
  26. End Sub
  27.  
I think this should be fairly straightforward, but I just don't know the syntax.
Jan 19 '11 #1
9 1758
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Hi there
Im not really familier with your way of using instanced forms, so this is a guess at a method to use. Modify the first function:
Expand|Select|Wrap|Line Numbers
  1. Function OpenAnIURClient(Optional strFilter as string="")
  2.     'Purpose:   Open an independent instance of form frmClient. 
  3.     Dim frm As Form 
  4.  
  5.     'Open a new instance, show it, and set a caption. 
  6.     Set frm = New Form_Sorted_by_IUR 
  7.     frm.Visible = True 
  8.     frm.Caption = frm.Hwnd & ", opened " & Now() 
  9.  
  10.     if strFilter & ""<>"" then
  11.       frm.Filter=strFilter
  12.       frm.FilterOn=True
  13.     end if
  14.     'Append it to our collection. 
  15.     clnIURClient.Add Item:=frm, Key:=CStr(frm.Hwnd) 
  16.  
  17.     Set frm = Nothing 
  18. end Function
And then call the function like:
Expand|Select|Wrap|Line Numbers
  1.  stLinkCriteria = "[IURs.IUR Index]=" & Me![IUR Index] 
  2.  OpenAnIURClient stLinkCriteria
Jan 21 '11 #2
NeoPa
32,557 Recognized Expert Moderator MVP
When using the syntax that opens multiple instances of a designed form in your database (Set frm = New Form_blahblah), you are specifically not using the normal syntax which would allow you specify stLinkCriteria (WhereCondition) or OpenArgs parameters. The former allows you to specify a filter condition to the instance of the form, and the latter allows you to pass across information that the code in your form can use for whatever it likes (in this case it might want to navigate to the specified record).

The options I can see are to :
  1. Apply a filter to the form externally -
    Expand|Select|Wrap|Line Numbers
    1. frm.Filter = "Blah blah"
    2. frm.FilterOn = True
  2. Design a public procedure in the form that you could call externally, passing the value of the required record -
    Expand|Select|Wrap|Line Numbers
    1. Call frm.YourPubProc("Blah blah")
    The procedure would take the necessary steps either to filter the data, or to navigate to the specified record. Your choice.

PS. This use of forms (multiple instances etc) is generally considered quite advanced stuff. I would guess very few Access programmers have ever used it. Just so you understand where you're at with this Sue. It's not super difficult once you get your head around it, but very few will have experience to share I expect.
Jan 21 '11 #3
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Im guessing the need to have multiple instances of the same form is that you want to have several windows(form) open at the same time? Is that the case?

Otherwise please do me a favour and explain why you use instanced forms.

TheSmileyCoder
Jan 21 '11 #4
NeoPa
32,557 Recognized Expert Moderator MVP
I can't answer for Sue, but the typical reason is the potential for multiple instances open together. This could include the requirement to have multiple windows doing an ostensibly similar job, but could also include a form of more generic use that would generally be used where necessary, with the possibility, in certain circumstances only, that more than one instance could be active concurrently. An example that comes to mind is an info form that indicates a certain state relative to another form. EG. that an activity is in process.
Jan 21 '11 #5
sueb
379 Contributor
Thanks to both of you for these ideas--I haven't had a chance to try them yet, but I thought I could at least clear up why I'm doing this. My users need to be able to review the records of multiple patients at one time, not for the purposes of comparing any of the data, but because their work flow is very interruptible: among other things, they both work on a single patient's record for a long period, and intermittently have to respond to phone interruptions about other patients' information.

If they can simply minimize one patient's window and then open a separate window, it really makes their lives easier.

Currently I have two different forms that are copies of each other: the "sub"-window is being called from the master record (that's the "Open_IUR_Subform_Click" module) and opens a specific window, and the "independent" window (that's "OpenAnIURClient") opens from the switchboard and just opens on the first record.

I really need to get rid of one of these windows and make it able to be opened either with or without a record pointer (keeping them in synch is driving me crazy!), so that's the point of this question.
Jan 21 '11 #6
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Thank you for taking the time to explain this. It makes good sense to attack the problem like you have.

Part of the reason (Besides the best access experts on the net) I browse through this forum is because I often see people attacking a problem in ways I didn't even think off. While I don't have an immediate need to use something like this I can imagine some areas of my applications where it would be Nice to Have, and certainly add value.

Thank you, I hope you get something working and report back here. If you run into more trouble, please come back :)
Jan 21 '11 #7
sueb
379 Contributor
TheSmileyOne, this fix was so fast and slick it almost knocked me off my chair as it went in! It works perfectly, and (always a plus) really neatened up the code.
Jan 21 '11 #8
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Im smiling to hear that :)
Jan 23 '11 #9
NeoPa
32,557 Recognized Expert Moderator MVP
But ... but ... You're always smiling!
Jan 23 '11 #10

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

Similar topics

1
3167
by: Richard Coutts | last post by:
I have a Continuous Form where each record has a button that activates another form that simplifies entering values into the record. The activated form has the equivalent of a "Done" button. I'd...
0
1094
by: Lisa Jones | last post by:
Hi Has anyone see this problem in ADO.Net when deleting a record (assuming that the table has identity increment Index) result in getting wrong index key if right after adding the record the table...
6
3784
by: MLH | last post by:
When the vehicle entry form (frmVehicleEntryForm) first opens, the additional owner SubForm control (frmAddnlOwnrListSubForm) is enabled. You can click on it and it will accept the focus. But after...
3
2401
by: Cylix | last post by:
I have a form that contains around 20 input elements, they have some onclick event on it. I would like to know how can I get the form element index when the onclick event fire. I found no...
2
2534
by: whitc26 | last post by:
Let me preface: I'm a novice, and have no programming experience. I have created an access database and have a few tables in it. I have created a form called "clients" This form opens up and...
5
3473
by: Bill | last post by:
This database has no forms. I am viewing an Access table in datasheet view. I'd like to execute a macro to execute a function (using "runcode"). In the function, I'll reading data from the record...
2
1775
by: BerkshireGuy | last post by:
I have a form that acts like a dashboard to show summarized data. Currently, this form gets its summarized values from a total's query. When the user selects to run the dashboard, they should be...
9
1830
momotaro
by: momotaro | last post by:
hi every one im trying to pass to a function an array with its index: //this is my struct typedef struct{ char word; int anagrams; }Word; //this is the prototype of the function: int...
1
3225
by: Martin Bentler | last post by:
Right now, I have a form, locked records, on which I have a CommandButton that opens a second form (much like the first) but open for editing, plus allowing the user to manipulate other areas of the...
3
8884
by: extrym | last post by:
I have 2 forms, "Staff" and "Security" (without the ""'s). The Staff form has the following fields: staff_ID staff_name staff_number staff_DOB priority The Security form contains the...
0
7188
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
7313
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...
1
6970
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5558
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4987
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3146
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1489
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.