Solved

ADO Recordset command .AddNew use with form

Posted on 2001-09-03
2
311 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
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…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

867 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

21 Experts available now in Live!

Get 1:1 Help Now