473,653 Members | 3,000 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Use selected record in Form B (acDialog Form) as go to criteria in Form A

10 New Member
Howdy all,

I have a form for entering data (Form A), on which is a cmd button that opens Form B in acdialog mode to allow me to enter/edit records that are being displayed on Form A.

After adding/editing a record on Form B (opened in acDialog mode), I want a cmd button on Form B to close Form B and then have Form A automatically take me to the record that was added/edited in Form B (Form A has a subform that I will then enter data into).

My experience with VBA is very limited so please provide details and descriptions.

My cmd button on Form B currently does everything I want it to do except for this issue. The code for the cmd button on Form B currently is:

*************** *************** *************** ******
Private Sub cmdCloseEventFo rm_Click()
On Error GoTo Err_cmdCloseEve ntForm_Click

'Set criteria record for frm_Camas_Data upon return
'*** STILL WORKING ON THIS--HELP

DoCmd.Close
'Refresh frm_Camas_Data
Forms!frm_Camas _Data.Requery
'Match cboEventName to Event Name
Forms!frm_Camas _Data!cboFindEv entAll = Forms!frm_Camas _Data![EventName]

Exit_cmdCloseEv entForm_Click:
Exit Sub

Err_cmdCloseEve ntForm_Click:
MsgBox Err.Description
Resume Exit_cmdCloseEv entForm_Click

End Sub
*************** *************** *************** ***********

Thanks for the help!!!
Nov 24 '06 #1
8 3858
NeoPa
32,568 Recognized Expert Moderator MVP
I'm not sure exactly what's wrong here, but my first instinct would be to move the 'Requery' after the line where you set up 'Forms!frm_Cama s_Data!cboFindE ventAll'.
Please ignore this advice (see below) - it's wrong.
Nov 25 '06 #2
MMcCarthy
14,534 Recognized Expert Moderator MVP
I'm not sure exactly what's wrong here, but my first instinct would be to move the 'Requery' after the line where you set up 'Forms!frm_Cama s_Data!cboFindE ventAll'.
No the order is right.

The Form A (frm_Camas_Data ) has to be requeried before the new record can be found.

To add the record you need to insert it into the table or query behind the aforementioned form.

eg.

Dim strSQL As String

strSQL = "INSERT INTO TableOrQueryNam e (Field List separated by commas) VALUES (" & Me.Value1 & ", " & Me. Value2 ... etc. & ");"

DoCmd.RunSQL
Nov 25 '06 #3
NeoPa
32,568 Recognized Expert Moderator MVP
Oh yes - my bad.
I understand the logic now - thx.
Nov 25 '06 #4
Ragbrai
10 New Member
Thanks for the respones but I don't think this is what I'm trying to make happen.

What needs to happen is that when the cmd button in Form B is clicked, Form B needs to close (which is does) and then in Form A (which remained open in the background since Form B was opend with acDialog) I want the form to automatically be updated with the record that was either edited/added when in Form B.

In other words, add record XYZ in Form B, click on cmd button and return to Form A with Form A showing record XYZ. Or edit record XYZ in Form B, click on cmd button and return to Form A with record XYS showing.

I would also add that the current code DOES update the records in Form A, thus I'm not sure the suggested code you provided is necessary.

Any other thoughts?

Thanks again!
Nov 25 '06 #5
MMcCarthy
14,534 Recognized Expert Moderator MVP
Forms are just a visual interface for the records in the tables and queries they are based on.

If Form B adding or updating the same record source then you just need to requery form A and use the DoCmd.FindRecor d or DoCmd.GoToRecor d.

You will have to set focus on Form A. Use one of the above to go to the record based on unique value on Form B while its still open then close Form B.


Thanks for the respones but I don't think this is what I'm trying to make happen.

What needs to happen is that when the cmd button in Form B is clicked, Form B needs to close (which is does) and then in Form A (which remained open in the background since Form B was opend with acDialog) I want the form to automatically be updated with the record that was either edited/added when in Form B.

In other words, add record XYZ in Form B, click on cmd button and return to Form A with Form A showing record XYZ. Or edit record XYZ in Form B, click on cmd button and return to Form A with record XYS showing.

I would also add that the current code DOES update the records in Form A, thus I'm not sure the suggested code you provided is necessary.

Any other thoughts?

Thanks again!
Nov 25 '06 #6
Ragbrai
10 New Member
This makes sense but how do I use criteria (the specific record value from one f the fields) from Form B (which closes) as the criteria in the FindRecord or GoTo commands. This is really the problem that I can't figure out. Is there a way to store the value of the Form B field in a temporary holding field so that it can then be used to find the identified record in Form A.

Please bear with me as my experinence with VBA is limited at best.
Nov 25 '06 #7
NeoPa
32,568 Recognized Expert Moderator MVP
There is only one way that I can think of that provides what you're after.
Design a public function in a (ordinary) module which allows you to set AND get the values you need.
I have one you're welcome to use but it was designed for sharing an unspecified number of parameters with a report.
Expand|Select|Wrap|Line Numbers
  1. 'RptParms sets and returns a set of parameters required by a report.
  2. 'Call with intSetGet=0 to set various parameters.
  3. 'Call with intSetGet>0 to return an individual parameter.
  4. Public Function RptParms(intSetGet As Integer, _
  5.                          ParamArray avarParams() As Variant) As Variant
  6.     Static avarParms() As Variant
  7.     Dim intIdx As Integer
  8.  
  9.     RptParms = 0
  10.     If intSetGet = 0 Then
  11.         intSetGet = UBound(avarParams) + 1 - LBound(avarParams)
  12.         If intSetGet < 1 Then
  13.             ReDim avarParms(1 To 1)
  14.             avarParms(1) = "Error"
  15.             Exit Function
  16.         End If
  17.         ReDim avarParms(1 To intSetGet)
  18.         For intIdx = 1 To intSetGet
  19.             avarParms(intIdx) = avarParams(intIdx - 1)
  20.         Next intIdx
  21.     Else
  22.         'If outside bounds then it drops through and is set to "Error"
  23.         On Error Resume Next
  24.         If avarParms(intSetGet) = "Error" Then
  25.             RptParms = "Error"                  'On Error
  26.         Else
  27.             RptParms = avarParms(intSetGet)
  28.         End If
  29.     End If
  30. End Function
Nov 26 '06 #8
Ragbrai
10 New Member
SOLUTION!

I must admitt that I couldn't follow the above advice, however, after much trial and error here is the solution that worked to solve the problem.
_______________ _______________ _______________ ______________
Private Sub cmdCloseEventFo rm_Click()
On Error GoTo Err_cmdCloseEve ntForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

DoCmd.Save

stDocName = "frm_Camas_Data "
stLinkCriteria = "[EventName]='" & Me.[EventName] & "'"

'This command updates database with current record
Me.Recordset.Mo ve (0)

'Opens frm_Camas_Data and goes to last record displayed in frm_Events
DoCmd.OpenForm stDocName, , , stLinkCriteria

'Close frm_Events
DoCmd.Close acForm, "frm_Events ", acSaveYes

Exit_cmdCloseEv entForm_Click:
Exit Sub

Err_cmdCloseEve ntForm_Click:
MsgBox Err.Description
Resume Exit_cmdCloseEv entForm_Click

End Sub
_______________ _______________ _______________ _______________ _
Dec 28 '06 #9

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

Similar topics

3
2647
by: Iain Miller | last post by:
I'm sure this ought to be simple but I can't make it work!! I have a form (based on a query) that holds information about an individual. Each individual has a Unique reference field called "MAAID" which is generated elsewhere on data entry. All works fine. In this form there is a sub form which lists "Notes" . I have a seperate Notes table which is linked by an identifier field "NoteAID" to the data on each individual.
5
5248
by: tdmailbox | last post by:
I have a form with a child form. In the child form there is a list of names that can grow quite large. On the parent form I want to display the first name from the child form. I set up a test box that is populated with the code =subfrm_media_review_sec_party.Form!first_name & " " & subfrm_media_review_sec_party.Form!last_name It works except that when I flip through the names it populates the parent form with the name of what ever...
8
12088
by: Zlatko Matiæ | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the combobox. What is the solution? Thank you in advance.
4
2801
by: acni | last post by:
I have the following peice of code to try and send an email to selected contacts in my form.The problem is this line: StrStore = DLookup("", "qrySelectEmail", "??????") This looks up the email field in the records returned for the query qrySelectEmail. The final bit needs to tell it to go to the first record the first time the loop runs, then the second record the second time the loop runs etc… But I cannot figure out a way to do this,...
4
2501
by: zack | last post by:
Any help with this would be greatly appreciated, as cannot work out how to resolve. I have a report called "3_Strikes". In its 'On open' event is command to also open a criteria form popup form called, "3_Strikes_Search". The purpose of the form is to allow input of data to filter the results of the report, (In this case mail-merged letters). The issue I have is that when I open the report via a command button, the "3_Strikes_Search"...
5
4999
AccessIdiot
by: AccessIdiot | last post by:
Argh! Just when I think everything is working and I am doing one final test before showing it to the guys I built the db for, Access throws out a weird message and won't let me add a record. But only SOMETIMES. I am getting "You cannot add or change a record because a related record is required in table "tbl_Entrianment". The only thing that relates the two tables in question is the Entrainment_ID WHICH I CAN SEE ON MY FORM. Let me back...
10
15318
by: sara | last post by:
Hi - I have been struggling with solution ideas for this now for almost 2 weeks, and have not been able to figure this out. I have a user who creates a Purchase Order (tblPOData). In some circumstances, this or another user must create an invoice to go with the PO (I know - that makes no sense, but this is the business case). I have the user go to a form to create the invoice:
7
4003
by: Ceebaby via AccessMonster.com | last post by:
Hi All Here's hoping someone can help me with this. I have a report based on a query where the criteria for 4 of the fields is set from an unbound form. I want the user to be able to select any combination of the combo boxes, some might not be selected etc etc. ie they may want to select the area and ward to show on the report but not the case officer or the property type
1
1388
by: BayZee | last post by:
I have a main form with a serach box and bound record boxes. When user enters criteria in a search box, the new form pops up that has a combo box with the list of accounts that satisfy search criteria. What I am having a problem with is to implement the following: After selecting an account in a combo box, the initial main form should display that record in bound boxes. It's been such a hurdle for me, I spent days and cannot figure out how to...
0
8811
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8704
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8470
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8590
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6160
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5620
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2707
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 we have to send another system
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.