Solved

Open forms with same record on a different form

Posted on 2013-01-17
2
471 Views
Last Modified: 2013-01-17
I have a Add New Record form and a Edit Resource Form.

Add Resource Form Fields: (Populated from a combo box that pulls from active directory)
Resource ID
First
Last
Full Name
Email

Edit Resource Form:
Resource ID
First
Last
Full Name
Email
Plus additional information that is needed to add in addition to what was populated from Active Directory.

I want to be able to:
1) Add a Resource.
2) Save and open a new form to edit and add additional information.
3) Open the Edit Resource Form using the same primary ID that is linked to all the data.  

This seems simple and all the code I have tried does not work.

Problem.  When I open up my form in "Edit Mode" by the same Resource ID, it opens the form in Edit mode and brings over the same Resource ID, however, when the form opens and a record displays by default it over rides what Resource ID is already there and now I have my new Resource ID linked to the old records Resource ID's information (First, Last, ect)

I want to be able to open a the second form, display all the records by the Resource ID, not just populate the Resource ID.

Here are both codes that I have tried:

Code 1: (standard access default)
----------------------------------------------------------------
Private Sub cmdEditOpen_Click()
On Error GoTo Err_cmdEditOpen_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmEditResources"
   
    stLinkCriteria = "[ResourceID]=" & "'" & Me![ResourceID] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdEditOpen_Click:
    Exit Sub

Err_cmdEditOpen_Click:
    MsgBox Err.Description
    Resume Exit_cmdEditOpen_Click
   
End Sub

Code 2:
-------------------------------------------------------------------
Private Sub cmdEdit_Click()
On Error GoTo Err_cmdEdit_Click

    DoCmd.OpenForm "frmEditResources", acNormal, , , acFormEdit
    [Forms]![frmEditResources]![ResourceID] = [Forms]![frmAddResources V2]![ResourceID]
    [Forms]![frmEditResources]![Last] = [Forms]![frmAddResources V2]![Last]
    [Forms]![frmEditResources]![First] = [Forms]![frmAddResources V2]![First]
    [Forms]![frmEditResources]![Full Name] = [Forms]![frmAddResources V2]![Full Name]
    [Forms]![frmEditResources]![Email] = [Forms]![frmAddResources V2]![Email]
     
Exit_cmdEdit_Click:
    Exit Sub

Err_cmdEdit_Click:
    MsgBox Err.Description
    Resume Exit_cmdEdit_Click
   
End Sub
-----------------------------------------------------------------------------------------------------------------------------------

If I combined the efforts on one form, it can get confusing for day to day users who may accidentally add a new user thinking they can search from the drop down.

If there is an easier suggestion, please let me know.

THANKS!
0
Comment
Question by:gracie1972
2 Comments
 
LVL 31

Accepted Solution

by:
Helen_Feddema earned 500 total points
ID: 38788787
I recommend using the same form for adding and editing.  Put a big "Add New Record" button in the form header or footer, and maybe make a dummy record that will sort to the beginning, in case you have users who will just start typing a new record in the first record that appears.  For severe cases, you could put some code on the BeforeUpdate event that pops up a message when this record is edited -- something like "Please select the correct record in the Select Record combo box, or click the New Record button to create a new record".  Searching is best done with an unbound combo box in the header, with code like this:

Private Sub cboSelect_AfterUpdate()
'Created by Helen Feddema 29-Apr-2011
'Last modified by Helen Feddema 29-Apr-2011

On Error GoTo ErrorHandler

   Dim strSearch As String

   'For text IDs
   strSearch = "[______ID] = " & Chr$(39) & Me.ActiveControl.Value _
      & Chr$(39)

   'For numeric IDs
   strSearch = "[______ID] = " & Me.ActiveControl.Value

   'Find the record that matches the control
   Me.Recordset.FindFirst strSearch

ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   MsgBox "Error No: " & Err.Number _
      & " in " & Me.ActiveControl.Name & " procedure; " _
      & "Description: " & Err.Description
   Resume ErrorHandlerExit

End Sub

Open in new window

0
 

Author Comment

by:gracie1972
ID: 38789158
@Helen_Feddema, is there a way to have the drop down that runs my code be hidden unless they select add new record?

I know in SSRS you can hide/unhide data, I was not sure I can use the same logic?

1) Add new record
2) Form clears for adding
3) drop down becomes visible to select from and my other drop down for searching becomes hidden.

Is this to complex?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now