Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ADO Recordset command .AddNew use with form

Posted on 2001-09-03
2
Medium Priority
?
369 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 240 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

610 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