Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What query to use when using ADDNEW?

Status
Not open for further replies.

custsoft

Programmer
Aug 29, 2000
41
I am using VB6 and ADO 2.5. When I open a recordset where I will be doing an addnew I have been using a select like "select * from database", which I assume fills the recordset with all of the records from the database. It seems like a waste to fill the recordset with old data when you just want to add a new record. Should I be using a different select query? Thanks for your help. Joe Baileys Harbor WI.
 
Don't use a query statement just use the tablename

With rsVoterData 'Establish Record Set Connection ,Cursor ,Lock And Table
.ActiveConnection = hDBConnect
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "Configuration" 'This is the table name
End With

hope this helps. If you choose to battle wits with the witless be prepared to lose.
[machinegun][ducky]
 
Use this - returns no records:

Select * From MyTable Where 1=0

Since this always returns False, an empty recordset is returned.
 
Thanks for taking the time to respond to my inquiry. In regard to not using a select in the open. I used the following: rv.Open "dogmstr", PetsCN, adOpenKeyset, adLockPessimistic but this returned all of the records in the database (I used the recordcount to see how many records where there).
In regard to the second reply where you select * where 1=0, I get "empty row cannot be inserted. row must have at least one column value set" error. Any thoughts? Thanks again. Joe
 
Have you thought about using just a plain old SQL INSERT statment?

The syntax is as follows

stSQL = "INSERT INTO tablename (Field1, field2, ...) VALUES (Value1, 'Value2', ...)"

then do a conn.execute stSQL

 
strSql = "Select * From dogmstr Where 1 = 0"

rv.Open strsql, PetsCN, adOpenKeyset, adLockPessimistic

With rv
.AddNew
!MyField1 = "Value1"
!MyField2 = "Value2"
.Update
.Close
End With
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top