i need your thoughts masters :)

icemonster

Registered User.
Local time
Today, 08:12
Joined
Jan 30, 2010
Messages
502
so basically, i have this code and it works fine, it's just that it made me realize something,
Code:
Set rs = CurrentDb.OpenRecordset("qry_PATIENTDETAILSBILLING1")
    rs.AddNew
    rs.Fields("PLASTNAME").Value = Me.txtPLastName
    rs.Fields("PFIRSTNAME").Value = Me.txtPFirstName
    rs.Fields("PSSN").Value = Me.txtPSSN
    rs.Fields("PSEX").Value = Me.txtPSex
    rs.Fields("PDOB").Value = Me.txtPDOB
    rs.Fields("PSTREET1").Value = Me.txtPStreet1
    rs.Fields("PSTREET2").Value = Me.txtPStreet2
    rs.Fields("PPHONE1").Value = Me.txtPPhone1
    rs.Fields("PPHONE2").Value = Me.txtPPhone2
    rs.Fields("PCITY").Value = Me.txtPCity
    rs.Fields("PSTATE").Value = Me.txtPState
    rs.Fields("PZIPCODE").Value = Me.txtPZipCode
    rs.Fields("PHHA").Value = Me.cboClientID
    rs.Fields("PADDEDBYUSERID").Value = gbl_UserID
    rs.Fields("PADDEDBYUSER").Value = gbl_User
    rs.Fields("PADDEDONDATETIME").Value = Now()
    rs.Update
    rs.Bookmark = rs.LastModified
    lngPatientID1 = rs!PATIENTID
    rs.Close
    Set rs = Nothing
    lngPatientID2 = lngPatientID1
Set rs = CurrentDb.OpenRecordset("tbl_PATIENTBILLING")
    rs.AddNew
    rs.Fields("BPATIENTID").Value = lngPatientID2
    rs.Fields("BBILLTYPEID").Value = Me.cboPBillType
    rs.Fields("BINSURANCENO").Value = Me.txtInsuranceNo
    rs.Update
    rs.Close
    Set rs = Nothing
    Me.pgPatientList.Visible = True
    Me.pgPatientList.SetFocus
    Me.lstPatient.SetFocus
    Me.lstPatient = lngPatientID
    Me.pgAddNewPatient.Requery
    startPatientList

what am thinking is, after the rs.bookmark = rs.lastmodified i am curios, what would happen, if 10 users clicked the same button at the same time?
 
LastModified is a property of the recordset. Each user would be opening their own recordset and thus get a unique number (presuming a properly split application of course).
 
FYI

so basically, i have this code and it works fine, it's just that it made me realize something
Did it also make you realise that you could be using a bound form instead?

Plus you could also be using the WITH block. E.g.:
Code:
Set rs = CurrentDb.OpenRecordset("qry_PATIENTDETAILSBILLING1")
[COLOR=Blue]With rs[/COLOR][COLOR=Red]
    .[/COLOR]AddNew
    [COLOR=Red]![/COLOR]PLASTNAME = Me.txtPLastName
    [COLOR=Red]![/COLOR]PFIRSTNAME = Me.txtPFirstName
[COLOR=Blue]End With[/COLOR]
 
As Paul indicated, the .LastModified is relative to the Recordset object variable. But I have to ask -- Why would you enter data through a Query object? While it is possible, it is often times less efficient to do so. In addition, since you are just ADDING data and using a recordset object to do it, I would suggest that you open EMPTY recordsets, something like this:

Set rs = CurrentDb.OpenRecordset("SELECT * FROM qry_PATIENTDETAILSBILLING1 WHERE 1=0")
.
.
.
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tbl_PATIENTBILLING WHERE 1=0")

---

Granted DAO recordsets do load up "lazily", but, why force the engine to even return 1 record when you are simply adding to the data.

So now with all that, often it is my preference to NOT use recordsets to add data if I don't have to -- I try to use SQL statements, then use @@Identity to get the AutoNumber of the record you just inserted. I prefer this technique because I have found it to be more efficient in many of the apps I have written. For an example of what I am often accustomed to writing, see the following sample:
Code:
Sub foo()
    
    Dim strSQL As String
    
    strSQL = "INSERT INTO someParentTable (TextField1, TextField2)" & _
             " VALUES (""" & Me.someTextControl & """,""" & Me.someOtherControl & """)"
    With CurrentDb
        
        .Execute strSQL, dbFailOnError
        
        strSQL = "INSERT INTO someChildTable (ParentId, TextField1, SomeDateField)" & _
                 " VALUES (" & .OpenRecordset("SELECT @@Identity").Fields(0) & _
                           ",""" & Me.someTextControl & """" & _
                           ",Now())"
        
        .Execute strSQL, dbFailOnError
        
    End With
End Sub

Hope all this gives you some ideas and alternatives as you continue to develop.
 

Users who are viewing this thread

Back
Top Bottom