need help here guys!
i want to open record from form1 and form1 composed of two listview namely listview1 and listview2
if i choose listview1 or listview2, form2 will appear and data will display in labels
then if listview1 was selected then save it on table 1st_sem and listview2 on table 2nd_sem

here's my code, once i click the save button nothing happens. what wrong with my code?

If Label1.Caption = ID_no And Label2.Caption = Null Then
    With Adodc1.Recordset
        .fields("fname") = labelfname.caption
        .fields("lname") = labellname.caption
        .Fields("grade") = cbgrade.Text
        .update
        MsgBox "1st Semester Grade Added", vbInformation, "Success"
        End With
        Exit Sub

elseif Label2.Caption = ID_no And Label1.Caption = Null Then
    With Adodc2.Recordset
         .fields("fname") = labelfname.caption
        .fields("lname") = labellname.caption
        .Fields("grade") = cbgrade.Text
        .update
        MsgBox "2nd Semester Grade Added", vbInformation, "Success"
        End With
        Exit Sub
else
        msgbox "invalid grade"
End If

Dani AI

Generated

A few short, practical notes that solve the common problems in this thread (thanks to for following up and for pointing to related discussion). The usual causes when a Save button appears to "do nothing" are: (1) comparing a label to Null instead of checking for an empty string or using IsNull, (2) not calling AddNew (or Edit) on the recordset before assigning fields, or (3) the recordset/ADODC is not pointing to the correct table. Passing a clear flag to the second form is the simplest way to tell it which table to write to.

A straightforward pattern: set a public property on the edit form (or use the form Tag) to indicate "1st_sem" or "2nd_sem". On Save, choose the correct recordset, call AddNew for new records (or Edit for existing), assign fields, then call Update. Example pattern:

' from Form1
Form2.SourceTable = "1st_sem"   ' or "2nd_sem"
Form2.Show

' in Form2 (declaration)
Public SourceTable As String

Private Sub cmdSave_Click()
    Dim rs As ADODB.Recordset
    If SourceTable = "1st_sem" Then
        Set rs = Adodc1.Recordset
    Else
        Set rs = Adodc2.Recordset
    End If

    rs.AddNew
    rs.Fields("fname").Value = Trim$(lblFname.Caption & "")
    rs.Fields("lname").Value = Trim$(lblLname.Caption & "")
    rs.Fields("grade").Value = Val(cbGrade.Text)
    rs.Update
    MsgBox "Saved to " & SourceTable
End Sub

Troubleshooting tips: step through the Save with the debugger to confirm which branch runs and what values are being written. Use Trim$(… & "") or Len(Trim$(… & "")) = 0 to test emptiness instead of comparing to Null. Verify ADODC.RecordSource/Connection and that field names and data types match. If recordset methods still fail, use a parameterized INSERT via ADODB.Command as an alternative and check for any runtime Err.Number/Err.Description to diagnose permission or SQL issues.

Recommended Answers

All 3 Replies

Have a look at this current Daniweb discussion here. It will give you all the options needed as per your question...

i opened you posted discussion, but i cant understand.
but just forget this post. ive already figured out my problem
thanks for the help

No problem.
Happy coding.

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.