Link to home
Start Free TrialLog in
Avatar of egovernment
egovernmentFlag for Afghanistan

asked on

DoCmd.GoToRecord , , acNewRec in ADO

What the command in ADO can do this statement DoCmd.GoToRecord , , acNewRec
Avatar of danishani
danishani
Flag of United States of America image

See below link usinge .AddNew command:
http://msdn.microsoft.com/en-us/library/ms677536%28v=vs.85%29.aspx

HTH,
Daniel
Avatar of David L. Hansen
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
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.
Avatar of egovernment

ASKER

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
The command should work as you posted it in your question.
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.
Are you using a bound form?
What is meaning bound form] ?
Open the form in design view and show the form properties.
In the Recordsource property , is there an entry?  What is it?
No entry found.
SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

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)

 
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
I already suggested using the .AddNew statement at the beginning ...
Because there no accurate answer and fast reply therefore I search in internet and found the complete answer with myself