Monday, November 21, 2016

Top 10 Using an ADO recordset with a form

How to delete a row
Set rs = Me.gridPhoneNumberDetail2.Form.Recordset
        If vbYes = MsgBox("Delete " & vbCrLf & strMsg, vbYesNo + vbInformation, "Confirm Action") Then
            rs.Delete
            If Not rs.EOF() Then rs.MoveNext
        End If
 

Set rs = Nothing

How to add a record?

Dim strSQL As String

If vbYes = MsgBox("Add a new requirement", vbInformation + vbYesNo, "Confirm action") Then
    strSQL = "INSERT INTO WJDPhoneNumber(PersonInfoId) VALUES(" & _
        Forms!wjdfrmpersoninfo!PersonInfoID & ")"
        CurrentDb.Execute strSQL
    Me.Refresh
End If

How to check if there are no rows in a form's DAO recordset

Dim rs As DAO.Recordset
Set rs = Me.gridPhoneNumberDetail2.Form.Recordset
Me.cmdDeleteRequirement.Enabled = rs.RecordCount > 0

How to set the width of a column in a subform
In the Form's Open event put the following code:

Private Sub Form_Open(Cancel As Integer)
Me.gridPhoneNumberDetail2.Form.Controls("PhoneNumber").ColumnWidth = 2160
End Sub

How to make a column invisible
in the form's Open event add:

Me.gridPhoneNumberDetail2.Form.Controls("Type").ColumnHidden = True



No comments: