Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 13th, 2008, 01:46 PM
Registered User
 
Join Date: Jan 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Synching values between forms

Hello,

My application requires that data entry people check to see if a contact already exists in the database before entering a new "contact log" incident.

I have created six search forms, each based on a separate parameter query. For example, the data entry person can begin by searching on "town" to see if there are any existing contacts from a particular town.

The search form works well. It displays every contact living in a town that corresponds to what the data entry person keystroked into the parameter dialog box.

The next step is for the data entry person to select a contact by clicking on the contact's ID, and then to click on my "Open Contact Log" command button.

The following code, attached to the button's "On Click" event opens the proper form and displays a record wherein the contact ID matches the one found in the search form:


Code:
Private Sub cmdOpenContactLog_Click()
On Error GoTo Err_cmdOpenContactLog_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmContactServicesLog"

    stLinkCriteria = "[VictimID]=" & Me![VictimID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Me![VictimID].SetFocus

    DoCmd.Close acForm, Me.Name

Exit_cmdOpenContactLog_Click:
    Exit Sub

Err_cmdOpenContactLog_Click:
    MsgBox Err.Description
    Resume Exit_cmdOpenContactLog_Click

End Sub
However, I need for the Contact form to open in a New Record, and to do so with the contact ID already populated with the contact ID selected in the search form.

When I add a "DoCmd.GoToRecord, , acNewRecord" line, the Contact form opens in a new record, but the contact ID field is blank.

How can I get the form to open in a new record and have the contact ID field match the contact ID field selected in the search form?

Thanks for all your help.



George M. Fodor
 
Old January 14th, 2008, 11:09 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Th way I usually do something like this is to create a public variable (in a module with all my public variables):

Public piContactID As Integer

I am assuming that this is an integer. Then do this:

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmContactServicesLog"
    piContactID = Me![VictimID]

    stLinkCriteria = "[VictimID]=" & Me![VictimID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    Me![VictimID].SetFocus

    DoCmd.Close acForm, Me.Name

Then the on Open event of your form would have:

If piContactID <> 0 Then
   Me.VictimID = piContactID
End If

piContactID = 0

Does that help?


mmcdonal

Look it up at: http://wrox.books24x7.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to access values from different windows forms? chobo2 C# 2008 aka C# 3.0 17 September 15th, 2008 05:31 PM
Can two forms share values within a function mat41 Javascript 8 March 4th, 2007 11:31 PM
Passing values between forms alok992 C# 1 April 28th, 2004 04:07 AM
Getting text box values between forms? cdnamm BOOK: Professional C#, 2nd and 3rd Editions 1 August 13th, 2003 11:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.