473,403 Members | 2,366 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,403 software developers and data experts.

when close a Pop-up form, keep main form on same record

Hello,
I know I've seen an answer to this question before, but I cannot seem to find it again. After searching for a few hours, I've decided to re-post in hopes someone can give advice and/or send me to an existing thread...

I have a main form with a number of subforms. On each subform there is a button that opens a Pop-up form where users can enter data. When I close the Pop-up form, however, the mainform/subform jump to the first record rather than staying at the same record. I know I should bookmark a recordset clone, but I am having trouble with the code because I'm going between two different forms. I want to save the ID from the Pop-up form and then find the record with that ID in the main form. I have a button that closes the Pop-up and figure I should add this code to the On_Click event, no?

I am trying to learn VBA, but am very slow, so if someone can recommend appropriate code, I would be very appreciative!

Thanks so much,
Bridget
Feb 15 '08 #1
11 2079
Delerna
1,134 Expert 1GB
I have a button that closes the Pop-up and figure I should add this code to the On_Click event, no?
Yes
One thing you could try is a public variable on your main form and then as you close the popup form you could set that variable to equal the ID from the popup.
Then you arrange so that when the mainform gets refreshed it uses the contents of the public variable to move to the correct record.

or another, probably better, possibility would be to add a public parameterised subroutine on your mainform. That way, in the on click event of the button you call that public sub passing the id in the parameter.

Does that help?
Feb 17 '08 #2
Hello Delerna,
Thank you for your reply!
Yes these options make sense. I am not very good with code however. (relatively new to Access). Would be able to suggest some code to implement this public variable / sub?

Bridget


Yes
One thing you could try is a public variable on your main form and then as you close the popup form you could set that variable to equal the ID from the popup.
Then you arrange so that when the mainform gets refreshed it uses the contents of the public variable to move to the correct record.

or another, probably better, possibility would be to add a public parameterised subroutine on your mainform. That way, in the on click event of the button you call that public sub passing the id in the parameter.

Does that help?
Feb 19 '08 #3
Delerna
1,134 Expert 1GB
yes here is a question very similar to yours.
Although you are going to need to use GotoRecord or something like that.

Have a go and if you have trouble post back here with what you have tried and what problem you are having and either I or someone else will be glad to assist.

PS Don't forget the help menu, theres some great stuff in there for learning the basics
Feb 19 '08 #4
yes here is a question very similar to yours.
Although you are going to need to use GotoRecord or something like that.

Have a go and if you have trouble post back here with what you have tried and what problem you are having and either I or someone else will be glad to assist.

PS Don't forget the help menu, theres some great stuff in there for learning the basics

Thank you Delerna! I will check that post. And thank you for the reminder about using Help!
Best,
Bridget
Feb 26 '08 #5
Thank you Delerna! I will check that post. And thank you for the reminder about using Help!
Best,
Bridget
Okay, I have made some progress. :)
However I'm still not quite able to do what I want... :(

I am able to open the main form and filter on the record currently displayed in teh pop up form. However, rather than filter, I would like to just go to that record.
Below (first) is the code that works to filter on the correct record and (Second)my attempt at using a recordset clone that did not work. I'm sure I'm doing something simple wrong. Any advice would be greatly appreciated!
Bridget

This code is in the "Done" button of the pop-up form.
In both forms, the objects are called txtBldgID and the control source is BldgID.

FIRST
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnDone_Click()
  2. On Error GoTo Err_btnDone_Click
  3.  
  4. 'opens main form and filters on record displayed in pop-up form
  5. DoCmd.OpenForm "frmTabs", , , "[BldgID] = " & Me.txtBldgID
  6.  
  7. 'closes pop-up form
  8. DoCmd.Close acForm, "frmAddBldgNm", acSaveYes
  9.  
  10. Exit_btnDone_Click:
  11.     Exit Sub
  12.  
  13. Err_btnDone_Click:
  14.     MsgBox Err.Description
  15.     Resume Exit_btnDone_Click
  16. End Sub
  17.  
SECOND
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnDone_Click()
  2. On Error GoTo Err_btnDone_Click
  3.  
  4. 'opens main form and filters on record displayed in pop-up form
  5. ' DoCmd.OpenForm "frmTabs", , , "[BldgID] = " & Me.txtBldgID
  6.  
  7. 'closes pop-up form
  8. ' DoCmd.Close acForm, "frmAddBldgNm", acSaveYes
  9.  
  10.    Dim rs As Object
  11.    Dim intBldgID As Integer
  12.  
  13.    intBldgID = Me.txtBldgID
  14.  
  15.    DoCmd.OpenForm "frmTabs"
  16.  
  17.    Set rs = Me.Recordset.Clone
  18.    rs.FindFirst "[BldgID] = " & intBldgID
  19.  
  20.    DoCmd.Close acForm, "frmAddBldgNm", acSaveYes
  21.  
  22. Exit_btnDone_Click:
  23.     Exit Sub
  24.  
  25. Err_btnDone_Click:
  26.     MsgBox Err.Description
  27.     Resume Exit_btnDone_Click
  28. End Sub
  29.  
Feb 26 '08 #6
Stewart Ross
2,545 Expert Mod 2GB
...Below (first) is the code that works to filter on the correct record and (Second)my attempt at using a recordset clone that did not work. I'm sure I'm doing something simple wrong.
Hi. There are only a few changes to your code needed to make the bookmark property work for you:
Expand|Select|Wrap|Line Numbers
  1. Dim rs As DAO.Recordset
  2. Dim intBldgID As Integer
  3. Dim FrmName as String
  4. intBldgID = Me.txtBldgID
  5. FrmName = "frmTabs" 
  6. DoCmd.OpenForm FrmName
  7. Set rs = forms(FrmName).Recordset.Clone
  8. rs.FindFirst "[BldgID] = " & intBldgID
  9. Forms(FrmName).Bookmark = rs.bookmark
  10.  
You were cloning the wrong recordset - the one from your pop-up instead of frmTabs - and you weren't setting the bookmark property in frmTabs to match the record found.

I assume there will always be a match between the pop-up form and the main form. If there is the possibility that there won't be a match this can be tested using
Expand|Select|Wrap|Line Numbers
  1. If rs.nomatch then...
-Stewart
Feb 26 '08 #7
Hi. There are only a few changes to your code needed to make the bookmark property work for you:
Expand|Select|Wrap|Line Numbers
  1. Dim rs As DAO.Recordset
  2. Dim intBldgID As Integer
  3. Dim FrmName as String
  4. intBldgID = Me.txtBldgID
  5. FrmName = "frmTabs" 
  6. DoCmd.OpenForm FrmName
  7. Set rs = forms(FrmName).Recordset.Clone
  8. rs.FindFirst "[BldgID] = " & intBldgID
  9. Forms(FrmName).Bookmark = rs.bookmark
  10.  
You were cloning the wrong recordset - the one from your pop-up instead of frmTabs - and you weren't setting the bookmark property in frmTabs to match the record found.

I assume there will always be a match between the pop-up form and the main form. If there is the possibility that there won't be a match this can be tested using
Expand|Select|Wrap|Line Numbers
  1. If rs.nomatch then...
-Stewart

It works beautifully. A thousand thank-you's! I had come up with a more clunky set of code that also worked, but this processes much faster and requires less code. For the forum's reference, I am posting the complete OnClick event code for the "Close" button of the Pop-Up form (FIRST) - based on Stewart's suggestion above - along with the alternate code that I had come up with (SECOND).

Again, thank you!!
Bridget

FIRST
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnDone_Click()
  2. 'Start error handling code.
  3. On Error GoTo Err_btnDone_Click
  4.  
  5. 'Define variables.
  6. Dim rs As DAO.Recordset
  7. Dim intBldgID As Integer
  8. Dim PopUpFrm As String
  9. Dim MainFrm As String
  10.  
  11. 'Store ID from pop-up form as variable.
  12. intBldgID = Me.txtBldgID
  13.  
  14. 'Define PopUpFrm name and close Pop-up form.
  15. PopUpFrm = "frmAddBldgNm"
  16. DoCmd.Close acForm, PopUpFrm
  17.  
  18. 'Define MainFrm name and open main form.
  19. MainFrm = "frmTabs"
  20. DoCmd.OpenForm MainFrm
  21.  
  22. 'Set recordset clone.
  23. Set rs = Forms(MainFrm).Recordset.Clone
  24.  
  25. 'Locate stored ID in the recordset.
  26. rs.FindFirst "[BldgID] = " & intBldgID
  27.  
  28. 'Move the bookmark on the main form to the stored ID bookmark.
  29. Forms(MainFrm).Bookmark = rs.Bookmark
  30.  
  31. 'Exit the sub
  32. Exit_btnDone_Click:
  33.     Exit Sub
  34.  
  35. 'Exit the error handling.
  36. Err_btnDone_Click:
  37.     MsgBox Err.Description
  38.     Resume Exit_btnDone_Click
  39.  
  40. End Sub
  41.  

SECOND
Expand|Select|Wrap|Line Numbers
  1. 'ALTERNATE CODE THAT WORKS, BUT IS NOT AS SLICK AS THE CODE ABOVE BASED ON THE POST BY STEWART.
  2. Private Sub btnDone_Click()
  3. 'Start the error check.
  4. On Error GoTo Err_btnDone_Click
  5.  
  6. 'Store the main form name as a string variable.
  7. Dim stDocName As String
  8. stDocName = "frmTabs"
  9.  
  10. 'Store the pop-up form's ID as a variable.
  11. strBldgID = Me!txtBldgID
  12.  
  13. 'Close the pop-up Form
  14. DoCmd.Close acForm, "frmAddBldgNm", acSaveYes
  15.  
  16. 'Open the main form and set the OpenArgs property to the ID variable "strBldgID"
  17. 'that stores the ID from the pop-up form that I want to locate.
  18.  
  19. DoCmd.OpenForm stDocName, , , , acFormPropertySettings, , strBldgID
  20.  
  21. 'Go to the ID control on the main form and set focus to it.
  22. Forms!frmTabs!txtBldgID.SetFocus
  23.  
  24. 'Find the first record on the main form that matches the stored ID from the pop-up form.
  25. DoCmd.FindRecord strBldgID, , True, , True, , True
  26.  
  27. 'Exit the sub
  28. Exit_btnDone_Click:
  29.     Exit Sub
  30.  
  31. 'Exit the error check.
  32. Err_btnDone_Click:
  33.     MsgBox Err.Description
  34.     Resume Exit_btnDone_Click
  35. End Sub
  36.  
Feb 26 '08 #8
RedSon
5,000 Expert 4TB
This post has been reported to moderator staff, the request has been to split it into to separate threads. However, I am not understanding why it needs to be split. I am happy to do it, if someone could provide some justification as to why I would be thankful.

Unless another moderator already split it and I didn't notice.
Feb 27 '08 #9
Stewart Ross
2,545 Expert Mod 2GB
This post has been reported to moderator staff, the request has been to split it into to separate threads. However, I am not understanding why it needs to be split. I am happy to do it, if someone could provide some justification as to why I would be thankful.

Unless another moderator already split it and I didn't notice.
Post has been split at some time following my request - see thread http://www.thescripts.com/forum/thread776091.html. Thanks for trying anyway.
-Stewart
Feb 27 '08 #10
Post has been split at some time following my request - see thread http://www.thescripts.com/forum/thread776091.html. Thanks for trying anyway.
-Stewart
Thanks for notifying me of the split.
Best,
Bridget
Feb 27 '08 #11
RedSon
5,000 Expert 4TB
Post has been split at some time following my request - see thread http://www.thescripts.com/forum/thread776091.html. Thanks for trying anyway.
-Stewart
Boy, those mods are fast!
Feb 27 '08 #12

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

Similar topics

9
by: Graham | last post by:
What I currently have is a page that opens another browser at 800x600, once that is loaded I would like to close the orginal page down while keeping the page that it has just opened open (To make...
7
by: Darren Grant | last post by:
Hi, Is it good style to use overload operator for a class which isn't really a container? Eg, I have a class BezierPop, which represents a population of Bezier curves (yes, we're talking...
45
by: Debashish Chakravarty | last post by:
K&R pg.66 describes two situations when using goto makes sense. Has anyone here come across situations where using goto provided the most elegant solution. --...
28
by: Sathyaish | last post by:
If fopen fails, is there a way to know why?
3
by: Kathy Burke | last post by:
I see plenty of examples of window.close javascript for a button or link click, but I would like to do is close the pop-up window when my submit code has completed successfully. Any suggestions?...
6
by: AussieRules | last post by:
Hi, When ever I run my app from within the vb.net ide, all goes fine, except when I exit the app. I get the following error twice in a row. When I select 'break' the Address of the problem is...
1
by: DJG79 | last post by:
Hi all, I am using an open source menu that i found and it works great, except for one thing that when the web page is not scrolled to the very top the drop down links will not stay visible. Has...
25
by: Nicholas Parsons | last post by:
Howdy Folks, I was just playing around in IDLE at the interactive prompt and typed in dir({}) for the fun of it. I was quite surprised to see a pop method defined there. I mean is that a...
6
by: tabakaka | last post by:
what is the condition if i want to pop a new window once i close the current one? is it..? if window.close { window.open("abc.aspx", "abc",...
3
by: Andrew Poulos | last post by:
From a window opener how can I know when a popup window's content has loaded? I tried: var pop = window.open(url, str); pop.onload = something; which triggers in some browsers but not in IE....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.