Solved

ADO Recordset command .AddNew use with form

Posted on 2001-09-03
2
308 Views
Last Modified: 2008-07-03
Hello,

I am developing an Access Project front-end and SQL Server back-end application.  

First I need to display a form which is ready for data entry, so I need to somehow move the recordset to display a new (empty) row.  

Is the following code the best way to display a blank row in a form and then insert a new record?
Private Sub Command3_Click()

    Dim cnn As ADODB.Connection
    Dim rcd As ADODB.Recordset
    Set rcd = New ADODB.Recordset
    Set cnn = CurrentProject.Connection
   
rcd.Open "Select * from Requests", cnn, adOpenKeyset, adLockOptimistic, adCmdText

    DoCmd.GoToRecord , , acNewRec
   
    With rcd
        .AddNew
        !Case_Patient_Num = txtCase_Patient_Num
        .Update
    End With

End Sub

0
Comment
Question by:accesslite_
2 Comments
 
LVL 3

Expert Comment

by:sbereli
ID: 6452272
Pretty good way, and safe as well.
0
 
LVL 6

Accepted Solution

by:
PsychoDazey earned 60 total points
ID: 6454665
The only suggestion I would make is to put the code that moves to the record and populates the field in the forms On_Load Event:
First you will have to Dim a Global Variable:
Global strPatientNum As String
Then, in your command button click event set it to rcd!Case_Patient_Num :
strPatientNum = rcd!Case_Patient_Num

Form On_Load()
DoCmd.GoToRecord , , acNewRec
txtCase_Patient_Num.Value = strPatientNum

I dont know if this way is better or safer, its just my preferred method.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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…
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

19 Experts available now in Live!

Get 1:1 Help Now