[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1624
  • Last Modified:

DoCmd.GoToRecord , , acNewRec in ADO

What the command in ADO can do this statement DoCmd.GoToRecord , , acNewRec
0
egovernment
Asked:
egovernment
  • 7
  • 7
  • 2
  • +1
2 Solutions
 
danishaniCommented:
See below link usinge .AddNew command:
http://msdn.microsoft.com/en-us/library/ms677536%28v=vs.85%29.aspx

HTH,
Daniel
0
 
David L. HansenProgrammer AnalystCommented:
The following example uses the GoToRecord method to make the seventh record in the Employees Form the current record:

DoCmd.GoToRecord acDataForm, "Employees", acGoTo, 7
0
 
peter57rCommented:
This has nothing to do with ADO, DAO or any other data access technology.

It is the code equivalent of clicking the New Record button on a bound form.

It doesn't matter whether the form is bound to a DAO or ADO recordset.
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
egovernmentAuthor Commented:
peter57r

Ok I want to make all objects on the form blank to allow user to add new values as what this statement do DoCmd.GoToRecord , , acNewRec
But not missing I read the data from SQL Server not Access
0
 
peter57rCommented:
The command should work as you posted it in your question.
0
 
egovernmentAuthor Commented:
Mr. peter57r

I was test the statement DoCmd.GoToRecord , , acNewRec inside a form in Access with reading the data from SQL Server but isnt work and I get error messege you can test that with yourself.
0
 
peter57rCommented:
Are you using a bound form?
0
 
egovernmentAuthor Commented:
What is meaning bound form] ?
0
 
peter57rCommented:
Open the form in design view and show the form properties.
In the Recordsource property , is there an entry?  What is it?
0
 
egovernmentAuthor Commented:
No entry found.
0
 
peter57rCommented:
So you must be using a unbound form - you must have code that displays the values from existing records and saves the values into ediyted or new records.

There is no concept of moving to a new record in an unbound form.  

You just clear the values from the form controls (set each one to Null or "")

I think you should describe how you are getting the data for the form and how you are displaying it.  Post the relevant code.
0
 
egovernmentAuthor Commented:
Mr. peter57r this is the code in form to get the data

Private Sub Form_Open(Cancel As Integer)
Dim cnn As ADODB.Connection
Dim vr_RdSet As New ADODB.Recordset

Set cnn = New ADODB.Connection
   
cnn.ConnectionString = "driver={SQL Server};" & _
"server=JRTQWER-41\SQLEXPRESS;uid=;pwd=;database=Test"
cnn.Open

   ' Find out if the attempt to connect worked.
    'If cnn.State = adStateOpen Then
      'MsgBox "Connect to the SQL Server!"
    'Else
      'MsgBox "Sorry. Connection failed"
    'End If
   
    vr_RdSet.Open "SELECT * FROM Test", cnn, adOpenStatic, adLockOptimistic
        
    Set Me.Recordset = vr_RdSet
        
    TextBox.ControlSource = "Test1"
    TextBox2.ControlSource = "Test2"
    
    Set vr_RdSet = Nothing
    Set cnn = Nothing
    
    'DoCmd.GoToRecord , , acNewRec
       
    'MsgBox "Finish."
End Sub
Private Sub Form_Unload(Cancel As Integer)
    Dim cnn As ADODB.Connection
    Set cnn = Me.Recordset.ActiveConnection
    cnn.Close
    Set cnn = Nothing
End Sub

Open in new window

0
 
peter57rCommented:
OK I see what you are doing.
I would expect the docmd.gotorecord to work, but maybe it's a problem with it being in the Open event; normally you have to use the load event to do initial navigation.

To see if that is the problem, you could try adding a command button to the form, using the wizard and choose the go to new record option.  If that works then move the Docmd code from the Open event to the Load event and try that.


Just a comment on the use of a disconnected recordset though - I trust you know how you plan to uodate the actual table with new records and changes.  It will take a lot of code, because as far as I know,  you cannot use the 'BatchUpdate' option for a form disconnected recordset ( only for a disconnected recordset updated in code)

 
0
 
egovernmentAuthor Commented:
I think I need 1 month in this site to found accurate answer anyway I found the answer in internet.

http://www.databasedev.co.uk/unbound-forms-add-data.html
0
 
peter57rCommented:
Sorry but we can only answer the question that you ask.

You asked a VERY specific question about Docmd.GoToRecord and that's what we were all looking at.

At no point did you say that you wanted to know how to add a new record to an unbound form.  In fact, the code you posted meant that you were not using a truly unbound form, as you were attaching the disconnected recordset to the form.  There is no real term to describe such a form, as it is neither a truly unbound form nor a truly bound form.  It has features of both types, but not all features of either type.

I'm glad you found the answer to your real question.
0
 
danishaniCommented:
I already suggested using the .AddNew statement at the beginning ...
0
 
egovernmentAuthor Commented:
Because there no accurate answer and fast reply therefore I search in internet and found the complete answer with myself
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 7
  • 7
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now