Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 3rd, 2006, 03:21 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: abu dbabi, , United Arab Emirates.
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default Add record

I have to make add new record button at access form.
table use sql server 2000 with odbc connection.

I make button by toolbar command button
when I click the button it give error message that
"you can't goto specified record"

what coding will use in button on click event ?
what change in properties ?

Second problem
--------------

I have a table with fied is ID.
I make data entry form.
I want that ID field should be auto insert record.
i.e. when insert the record ID field auto insert the
next number ?
ie 1, 2, 3, .......

what changing in table field / form properties ?

 regards

Mateen





  #2 (permalink)  
Old October 3rd, 2006, 06:53 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

For the first issue, I use code something like this, taking values from the form:

Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim stUID As String
Dim stPWD As String
Dim sValue1 As String
Dim sValue2 As String

stUID = "User"
stPWD = "********"

sValue1 = Me.txtTextControl
sValue2 = Me.SomeOtherControl

Set cnn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cnn.Open "DSN=WPM;", stUID, stPWD
rs.CursorLocation = 3

rs.Open "SELECT * FROM tblSQLTable", cnn, 3, 3

rs.AddNew
rs("FieldName1") = sValue1
rs("FieldName2") = sValue2
...

rs.Update

rs.Close
cnn.Close


As to the second issue, I generally let SQL supply the autonumber by setting the PK field to Identity, and giving it a starting number 1, seed 1. If you can't do this, and you are not worried about errors, then you can create a view on the PK of the table, and set it to order DESC, and SELECT TOP 1. Then take that value and add one to it before updating the table. I would use a view instead of a pass-through query since SQL will optimize the view, but not the query.

Did that help?


mmcdonal


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add record form bunkerbang Access VBA 5 September 12th, 2007 12:17 AM
how to add new record as first record in dataset hunzian78@yahoo.com ASP.NET 1.0 and 1.1 Professional 4 April 21st, 2006 05:23 AM
Help with Add record topshed Classic ASP Basics 6 February 7th, 2006 02:59 AM
Cannot add new record geolando Access 0 June 27th, 2005 06:23 PM
Add New compliling, but not actually adding record Louisa VB.NET 2002/2003 Basics 1 January 12th, 2004 11:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.