Solved

Add record

Posted on 2011-02-21
9
274 Views
Last Modified: 2012-06-21
Experts,

I have this form in continuous forms format with a listing of records for  a Company.
To add a record, I have to press a button and it will add based on the EndUserID and ProjID of the record a user has clicked on.

The issue is that a user usually scrolls to the bottom of the form and clicks in the NEW RECORD row and starts to add data.  If done this way then the EndUserID and ProjID are not associated with that record and the record just added woudl be unassociated and would not appear under the EndUserID and ProjID.  

If a user was to click in the NEW RECORD row then in effect what I would be looking for is a solution to add the EndUserID and ProjID

Any ideas on how to do this?  I hope the explanation is sufficient..pls ask if need more details.

Thank you
here is the code under the ADD RECORD button: (I also have ON LOAD event in the form and will post)

Private Sub cmdAddRecord_Click()

        Dim lngEndUserID As Long
    Dim lngPrjID As Long

On Error GoTo cmdAddRecord_Click_Err

If Me.NewRecord Then
  MsgBox "You're already at a New Record"
  Exit Sub
End If

If Not IsNull(Me.EndUserID) Then
   lngEndUserID = Me.EndUserID
   lngPrjID = Me.ProjectID
   
End If

    On Error Resume Next
    DoCmd.GoToRecord , , acNewRec
    If (MacroError <> 0) Then
        Beep
        MsgBox MacroError.Description, vbOKOnly, ""
    End If

Me.EndUserID = lngEndUserID
Me.ProjectID = lngPrjID

Me.Refresh

cmdAddRecord_Click_Exit:
    Exit Sub

cmdAddRecord_Click_Err:
    MsgBox Error$
    Resume cmdAddRecord_Click_Exit
   
End Sub

0
Comment
Question by:pdvsa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 

Author Comment

by:pdvsa
ID: 34944270
here is the ON LOAD event:
Private Sub Form_Load()

    DoCmd.Maximize
   
   
    If Nz(Me.OpenArgs, "") <> "" Then
    If Not Me.NewRecord Then
    Me.Filter = "[ProjectID] = " & Split(Me.OpenArgs, ";")(0) & " AND [EndUserID] = " & Split(Me.OpenArgs, ";")(1)
       Me.FilterOn = True
     Else
        '/this is a new record
        'MsgBox Split(Me.OpenArgs, ";")(2)

        Me.ProjectID = Split(Me.OpenArgs, ";")(0)
        Me.EndUserID = Split(Me.OpenArgs, ";")(1)
     End If
End If
End Sub

0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 34944359
The usual approach for this type of situation is to put code on the BeforeInsert event of the form, that would write the appropriate values to the fields.  This event fires when the first data is entered into the new record.
0
 
LVL 31

Accepted Solution

by:
Helen_Feddema earned 500 total points
ID: 34944384
You seem to be getting the ProjectID and EndUserID value from the same record you are trying to write to.  Best to set these variables from the the Load event, and then write them from the BeforeInsert event.  That is, if they are supposed to be the same for all the records on the Continuous form.  We may need more information on how your tables and forms are set up.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 34944394
You could also use the form's Tag property to store the IDs, and get them from that property in the BeforeInsert event.
0
 

Author Comment

by:pdvsa
ID: 34944670
Helen, thanks,... this seems to be exactly the solution.
<You seem to be getting the ProjectID and EndUserID value from the same record you are trying to write to.  Best to set these variables from the the Load event, and then write them from the BeforeInsert event.
==> Yes and how do you suggest I set those values?  

thank you
0
 

Author Comment

by:pdvsa
ID: 34944677
I know you mentioned teh TAG property too....I am looking for the easiest...I have no experience with TAG.
0
 

Author Comment

by:pdvsa
ID: 34945615
Helen,

I think I did it.  

I added, BeforeInsert:
        Me.ProjectID = Split(Me.OpenArgs, ";")(0)
        Me.EndUserID = Split(Me.OpenArgs, ";")(1)

and it seems to be working as if I pressed teh Add Record button.  

Let me know if you think I could have missed something.  

pdvsa.
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 34945658
Yes, that should do it.  
0
 

Author Comment

by:pdvsa
ID: 34945699
I applied that to 3 other forms and makes life a lot easier... what an easy fix.  thank you
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

734 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