Question TWO
I have on and off been using Basic, now VB since “the stone age” long before Microsoft and Windows. However it is only now I enter the issue of using VB6 and a database. I use VB6-ADO-ACCESS plus using DataGrid as the main view to see the database. I use 5 tables with some info in one table to be used in another. Hope it is OK to ask few questions but will put them one by one:

2. I have a button that with the code: DataList.Recordset.AddNew
But if I do not want to fill in the info in runtime I get an error message: "Empty row cannot be inserted.Row must have at least one column value set." Any suggestions?

Per

Dani AI

Generated

— The ADO error you see happens because AddNew creates a new (unsaved) row but does not write anything to the database until a field is given a value and Update is called. If you call Update while every field is still empty/NULL, the provider rejects the insert with "Empty row cannot be inserted. Row must have at least one column value set." For details on how AddNew behaves (and the FieldList/Values option that posts immediately), see the ADO AddNew documentation. (See: AddNew method (ADO).)

The "Expected Function or variable" compile error you reported usually means the line starting with a dot is not inside a With block or the call is not fully qualified. Either use a With ... End With around the recordset before using a leading dot, or call the method with the full object name. Microsoft documents that error and the usual causes: Expected Function or variable.

Practical fixes (build on and ): 1) If users can abandon the new row, cancel the pending insert instead of updating — use the Recordset.CancelUpdate method when you detect no values (CancelUpdate discards the new row). 2) If you want to create a row programmatically, pass FieldList/Values to AddNew so at least one column is set and ADO will post immediately. 3) If controls are bound, ensure DataField/DataSource are correct and validate controls before calling Update. See the CancelUpdate guidance and the Update/Cancel example for patterns to detect and discard pending adds. (See: CancelUpdate method (ADO) and Update and CancelUpdate example.)

These steps avoid creating empty rows and explain why the compiler error appears when a leading dot is used outside a proper object/With context.

Recommended Answers

All 4 Replies

Question TWO

2. I have a button that with the code: DataList.Recordset.AddNew
But if I do not want to fill in the info in runtime I get an error message: "Empty row cannot be inserted.Row must have at least one column value set." Any suggestions?

Per

The AddNew command just moves the cursor to a new record. you must then add your data to the fields and then save the record. You will want to have the new data ready to go:

Field1_Data = InputBox("Field1")
Field2_Data = InputBox("Field2")
etc...

[INDENT]With DataList.Recordset
[INDENT].AddNew
!Field1 = Field1_Data
!Field2 = Field2_Data
etc...
.Update[/INDENT]
End With[/INDENT]

Luck!

OK, thanks however was not able to get it right.

Gets error "Expected Function or variable".

Marked is "Private Sub ..." with yellow and
marked with blue is on the first line ".AddNew"

So what have I missed?

Have a nice day
Per

Hi,
Can u post your coding to view somebody to tell the suggestions.

Hi..go to prorties of each text box tht u hv added in the form in that go to datasource click and selct data source and in data field select the rows of database u hv created

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.