Solved

Add record

Posted on 2011-02-21
9
271 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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.

777 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