i need a code to enter data into a textbox and update an access database table which must be displayed in my listbox, please help
i also want to know hoe to search data in the table

Dani AI

Generated

A short, practical primer that expands on the thread: wanted to save textbox input into Access and show it in a list; and pointed toward VB6 data controls and the data-form wizard. Those are valid paths, but updates often fail for a handful of predictable reasons. The checklist below shows what to verify and a safer alternative approach.

Checklist for using the VB6 Data control and bound textboxes

  • Make sure the Data control’s DatabaseName points to the correct .mdb/.accdb file and the RecordSource is exactly the table or query name (no accidental leading/trailing spaces).
  • Bind each textbox to the control/field (so typing goes into the record buffer) and use the data-control navigation/save UI or a save action so the record actually gets written.
  • Standard VB6 ListBox is not automatically data-bound; either use a data-aware grid/control or populate the ListBox by re-running your SELECT and adding items programmatically after each change. (vbtutor.net)

If you want more control and fewer binding surprises, use ADO: open an ADODB connection (use the Jet provider for older .mdb files or ACE for .accdb), run parameterized INSERT/UPDATE commands, then re-query and refill the list. This avoids ambiguous “record buffer” states and makes refresh logic explicit. Also remember that new/edited record changes are not final until the data-layer save is invoked, so your UI must perform that save before you repopulate the list. (learn.microsoft.com)

Quick debugging notes (based on @Needu): a leading space in the RecordSource, an unset DatabaseName, controls that are not bound, a read-only file location (Program Files / UAC), or using the wrong provider for .accdb are the most common causes. Verify properties at runtime, try a SELECT in Access to confirm the table exists, and repopulate the listbox from a fresh query after saving.

Recommended Answers

All 5 Replies

to enter a data in textbox:
place a command button and data object and connect the database write code in command button.
"data1.recordset.addnew"
this code save data in the database.
data1.refresh
it update data.
connect the listbox with database. for search data write this code:


Dim Searchit As String
Dim Founder As Boolean

Searchit = UCase(InputBox("Enter name:", "Edit"))
If Len(Searchit) > 0 Then
'add this line
Data1.Refresh
Data1.Recordset.MoveFirst
Founded = False
End If

Do While (Not Founder) And (Not Data1.Recordset.EOF)
'u can add UCASE i just removed it for my query
If UCase(Data1.Recordset.Fields("name").Value) = Searchit Then
Founder = True
Exit Sub
End If
Data1.Recordset.MoveNext
Loop

If Not Founder Then
MsgBox "Unable to find the required item", , "Not Found"
Data1.Recordset.MoveLast
End If

i need the code for vb6

all this code is for vb6.

>all this code is for vb6. and the DAODC AKA Data1

Use the data form wizard, of which you will find under add-ins>add-in manager. Start a new standard exe project and then run the wizard as many times as necessary so that you have selected each form type and use each class/code/control. Save this as an example project and modify form1 to startup the other forms and that way you can walk through the code of each form type with F8.


Good Luck

i m not able to update my data using below program ....
please check and do needfull for me.....

Private Sub Command1_Click()
Data1.Recordset.AddNew
End Sub

Private Sub Command2_Click()
Data1.Recordset.Update
End Sub

Private Sub Command3_Click()
Data1.Recordset.Edit
End Sub

Private Sub Command4_Click()
Data1.Recordset.Delete
Text1.Text = ""
Text2.Text = ""
Data1.Refresh
End Sub

Private Sub Command5_Click()
Data1.RecordSource = " Table1"
Data1.Refresh
End Sub

Private Sub Command6_Click()
End
End Sub

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.