Solved

ADO Recordset command .AddNew use with form

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

813 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

13 Experts available now in Live!

Get 1:1 Help Now