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
11 2079
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?
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?
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
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
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 -
Private Sub btnDone_Click()
-
On Error GoTo Err_btnDone_Click
-
-
'opens main form and filters on record displayed in pop-up form
-
DoCmd.OpenForm "frmTabs", , , "[BldgID] = " & Me.txtBldgID
-
-
'closes pop-up form
-
DoCmd.Close acForm, "frmAddBldgNm", acSaveYes
-
-
Exit_btnDone_Click:
-
Exit Sub
-
-
Err_btnDone_Click:
-
MsgBox Err.Description
-
Resume Exit_btnDone_Click
-
End Sub
-
SECOND -
Private Sub btnDone_Click()
-
On Error GoTo Err_btnDone_Click
-
-
'opens main form and filters on record displayed in pop-up form
-
' DoCmd.OpenForm "frmTabs", , , "[BldgID] = " & Me.txtBldgID
-
-
'closes pop-up form
-
' DoCmd.Close acForm, "frmAddBldgNm", acSaveYes
-
-
Dim rs As Object
-
Dim intBldgID As Integer
-
-
intBldgID = Me.txtBldgID
-
-
DoCmd.OpenForm "frmTabs"
-
-
Set rs = Me.Recordset.Clone
-
rs.FindFirst "[BldgID] = " & intBldgID
-
-
DoCmd.Close acForm, "frmAddBldgNm", acSaveYes
-
-
Exit_btnDone_Click:
-
Exit Sub
-
-
Err_btnDone_Click:
-
MsgBox Err.Description
-
Resume Exit_btnDone_Click
-
End Sub
-
...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: -
Dim rs As DAO.Recordset
-
Dim intBldgID As Integer
-
Dim FrmName as String
-
intBldgID = Me.txtBldgID
-
FrmName = "frmTabs"
-
DoCmd.OpenForm FrmName
-
Set rs = forms(FrmName).Recordset.Clone
-
rs.FindFirst "[BldgID] = " & intBldgID
-
Forms(FrmName).Bookmark = rs.bookmark
-
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
-Stewart
Hi. There are only a few changes to your code needed to make the bookmark property work for you: -
Dim rs As DAO.Recordset
-
Dim intBldgID As Integer
-
Dim FrmName as String
-
intBldgID = Me.txtBldgID
-
FrmName = "frmTabs"
-
DoCmd.OpenForm FrmName
-
Set rs = forms(FrmName).Recordset.Clone
-
rs.FindFirst "[BldgID] = " & intBldgID
-
Forms(FrmName).Bookmark = rs.bookmark
-
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
-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 -
Private Sub btnDone_Click()
-
'Start error handling code.
-
On Error GoTo Err_btnDone_Click
-
-
'Define variables.
-
Dim rs As DAO.Recordset
-
Dim intBldgID As Integer
-
Dim PopUpFrm As String
-
Dim MainFrm As String
-
-
'Store ID from pop-up form as variable.
-
intBldgID = Me.txtBldgID
-
-
'Define PopUpFrm name and close Pop-up form.
-
PopUpFrm = "frmAddBldgNm"
-
DoCmd.Close acForm, PopUpFrm
-
-
'Define MainFrm name and open main form.
-
MainFrm = "frmTabs"
-
DoCmd.OpenForm MainFrm
-
-
'Set recordset clone.
-
Set rs = Forms(MainFrm).Recordset.Clone
-
-
'Locate stored ID in the recordset.
-
rs.FindFirst "[BldgID] = " & intBldgID
-
-
'Move the bookmark on the main form to the stored ID bookmark.
-
Forms(MainFrm).Bookmark = rs.Bookmark
-
-
'Exit the sub
-
Exit_btnDone_Click:
-
Exit Sub
-
-
'Exit the error handling.
-
Err_btnDone_Click:
-
MsgBox Err.Description
-
Resume Exit_btnDone_Click
-
-
End Sub
-
SECOND -
'ALTERNATE CODE THAT WORKS, BUT IS NOT AS SLICK AS THE CODE ABOVE BASED ON THE POST BY STEWART.
-
Private Sub btnDone_Click()
-
'Start the error check.
-
On Error GoTo Err_btnDone_Click
-
-
'Store the main form name as a string variable.
-
Dim stDocName As String
-
stDocName = "frmTabs"
-
-
'Store the pop-up form's ID as a variable.
-
strBldgID = Me!txtBldgID
-
-
'Close the pop-up Form
-
DoCmd.Close acForm, "frmAddBldgNm", acSaveYes
-
-
'Open the main form and set the OpenArgs property to the ID variable "strBldgID"
-
'that stores the ID from the pop-up form that I want to locate.
-
-
DoCmd.OpenForm stDocName, , , , acFormPropertySettings, , strBldgID
-
-
'Go to the ID control on the main form and set focus to it.
-
Forms!frmTabs!txtBldgID.SetFocus
-
-
'Find the first record on the main form that matches the stored ID from the pop-up form.
-
DoCmd.FindRecord strBldgID, , True, , True, , True
-
-
'Exit the sub
-
Exit_btnDone_Click:
-
Exit Sub
-
-
'Exit the error check.
-
Err_btnDone_Click:
-
MsgBox Err.Description
-
Resume Exit_btnDone_Click
-
End Sub
-
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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.
--...
|
by: Sathyaish |
last post by:
If fopen fails, is there a way to know why?
|
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?...
|
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...
|
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...
|
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...
|
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",...
|
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....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| | |