473,413 Members | 1,700 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,413 software developers and data experts.

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

10
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 cmdCloseEventForm_Click()
On Error GoTo Err_cmdCloseEventForm_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!cboFindEventAll = Forms!frm_Camas_Data![EventName]

Exit_cmdCloseEventForm_Click:
Exit Sub

Err_cmdCloseEventForm_Click:
MsgBox Err.Description
Resume Exit_cmdCloseEventForm_Click

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

Thanks for the help!!!
Nov 24 '06 #1
8 3843
NeoPa
32,556 Expert Mod 16PB
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_Camas_Data!cboFindEventAll'.
Please ignore this advice (see below) - it's wrong.
Nov 25 '06 #2
MMcCarthy
14,534 Expert Mod 8TB
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_Camas_Data!cboFindEventAll'.
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 TableOrQueryName (Field List separated by commas) VALUES (" & Me.Value1 & ", " & Me. Value2 ... etc. & ");"

DoCmd.RunSQL
Nov 25 '06 #3
NeoPa
32,556 Expert Mod 16PB
Oh yes - my bad.
I understand the logic now - thx.
Nov 25 '06 #4
Ragbrai
10
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 Expert Mod 8TB
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.FindRecord or DoCmd.GoToRecord.

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
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,556 Expert Mod 16PB
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
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 cmdCloseEventForm_Click()
On Error GoTo Err_cmdCloseEventForm_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.Move (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_cmdCloseEventForm_Click:
Exit Sub

Err_cmdCloseEventForm_Click:
MsgBox Err.Description
Resume Exit_cmdCloseEventForm_Click

End Sub
__________________________________________________ ___________
Dec 28 '06 #9

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

Similar topics

3
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...
5
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...
8
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...
4
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...
4
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...
5
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...
10
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...
7
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...
1
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...
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: 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
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...
0
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
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...

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.