Save Item in listbox to table please help

koketsomaseko

Registered User.
Local time
Today, 17:00
Joined
Jun 17, 2014
Messages
11
Please help me with the code to save data in listbox to a table in vba access
 

Attachments

  • Capture.PNG
    Capture.PNG
    21.9 KB · Views: 306
  • Capture2.PNG
    Capture2.PNG
    7.9 KB · Views: 261
Here is an example of code that you could edit to suit your needs.
'Insert into tblReportLog Form Values.



Dim strSQL As String

strSQL = "INSERT INTO tblReportLog (lrptdte,lsentto,lsubject,lmessage,lbcc, lrptname,loutputtype ) "
strSQL = strSQL & "VALUES (#" & Me.rdtesent & "#,'" & Me.EmailTo & "','" & Me.EmailSubject & "','" & Me.EmailMessage & "','" & Me.cbobcc & "','" & Me.txtrptname & Me.txtextension & "','""')"


CurrentDb.Execute strSQL, dbFailOnError


HTH
 
Without knowing the name of your listbox, the name of the table you want to insert to, rowsource of your listbox or the visible columns this is a suggestion for a solution, you will need to modify it accordingly.

Code:
currentdb.execute("INSERT INTO myTable (Major, Time, Ne, Escalation, Description) VALUES('" & myListBox.column(1) & "', " & myListBox.column(2) & ", '" & myListBox.column(3) & "', '" & myListBox.column(4) & "', '" & myListBox.column(5) & "')")
This will only work if you have selected a row in the rowsource before clicking the save button. So you may want to disable this button until a row has been selected
 

Users who are viewing this thread

Back
Top Bottom