1. User open "frm_company" to check whether any invoice issued or
not.
There is an invoice search button which triggers following code;
Dim rs As Recordset
Dim strSQL As String
strSQL = "SELECT tbl_transaction.transcid FROM tbl_transaction
" Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
_______________
If I change this to Dynaset, code doesn't show
transaction in
subform
rs.FindFirst "transcid = " & Me![cid]
This checks matching company Id in table transaction.
This is ridiculously inefficient. There are two approaches that are
much more efficient:
1. put the FindFirst criteria in your SQL and then check for
..RecordCount = 0.
2. don't check at all, and have the OnOpen event of your form tell
the user if there are no records.
Here's what your code would look like for the first approach:
Dim rs As Recordset
Dim strSQL As String
strSQL = "SELECT tbl_transaction.transcid FROM tbl_transaction "
strSQL = strSQL & "WHERE [transcid=" & Me!cid
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
If rs.RecordCount 0 Then
MsgBox "No Invoice Issued To This Company!", _
vbOKOnly + vbCritical, "No Record"
Else
DoCmd.OpenForm "frm_transaction_history", , , _
"[cid]=" & Me!cid
DoCmd.Close acForm, Me.Name
End If
The second approach would just open the form *hidden*:
DoCmd.OpenForm "frm_transaction_history", , , _
"[cid]=" & Me!cid, , acHidden
Then in the form's OnOpen event:
If Me.RecordsetClone.RecordCount = 0
MsgBox "No Invoice Issued To This Company!", _
vbOKOnly + vbCritical, "No Record"
Cancel = True
Else
Me.Visible = True
End If
That takes care of it and means you don't have to do a lookup before
you open the form. This is the type of method I always use (though
not exactly this simple).