Solved

Add record

Posted on 2011-02-21
9
269 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
  • 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
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, when working with VBA, learn some techniques for writing readable and easily maintained code.

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

20 Experts available now in Live!

Get 1:1 Help Now