thtadthtshldntb
Registered User.
- Local time
- Today, 10:05
- Joined
- Oct 29, 2014
- Messages
- 20
Hello Everyone,
I am (have to) use Access 2007 to create and run a database to deal with monthly stats from one of our EMRs.
One of the things that I have to do is normalize all the different ways that the staff free text these entries in for referring provider.
So what I did was create a table with all provider name variants that I update as I find new variations and then wrote this (with help)
It works as intended, however whenever I run the function, I get an access notice/error in VBA stating that I cannot save changes to my code because I no longer have exclusive access.
This of course goes away when I close and reopen. This is a really annoying thing when I am tweaking the code. Also, if I run it via macro with all tables and vba closed it still does this error.
I have some more tweaking to do to move it to the live tables.
I have searched around the net and the only thing that comes up is that the currentdb function is causing some sort of lockup issue. But I don't know.
Any input is appreciated.
I am (have to) use Access 2007 to create and run a database to deal with monthly stats from one of our EMRs.
One of the things that I have to do is normalize all the different ways that the staff free text these entries in for referring provider.
So what I did was create a table with all provider name variants that I update as I find new variations and then wrote this (with help)
Code:
Function UpdateProviders()
'declare variables
DAO.DBEngine.SetOption DAO.dbMaxLocksPerFile, 100000000
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim UPArray() As String
Dim icounter As Long
Dim actrecords As Integer 'will store total value of actual records
Dim strProvTable, strSQL As String
'Providr table SQL
strProvTable = "SELECT vpProviderNames.[LastName], vpProviderNames.[FirstName], vpProviderNames.[FullName], vpProviderNames.[KeeporReplace]" & _
"FROM vpProviderNames;"
'different saved values for strSQL
'strSQL = "SELECT testvpExamlist.[Referring Physician]" & _
"FROM testvpExamlist;"
'strSQL = "Select testvpimporteddata.[Referring Physician]" & _
"From testvpimporteddata;"
strSQL = "SELECT testvpimporteddata.[Performing Physician], testvpimporteddata.[Reading Physician], testvpimporteddata.[Referring Physician]" & _
"FROM testvpimporteddata;"
'open recordsets
Set db = CurrentDb
Set rs = db.OpenRecordset(strProvTable, dbOpenDynaset, dbSeeChanges)
'count actual providers and add them to UPArray
If Not rs.EOF Then
actrecords = 0
rs.MoveFirst
Do Until rs.EOF 'finds number of actual providers in list
If rs.Fields("KeeporReplace") = 1 Then
actrecords = actrecords + 1
End If
rs.MoveNext
Loop
'Debug.Print "total actual records = " & " " & actrecords
rs.MoveFirst
icounter = 0
ReDim UPArray(actrecords, 3)
Do Until rs.EOF
If rs.Fields("KeeporReplace") = 1 Then
If Not IsNull(rs.Fields("LastName")) Then
UPArray(icounter, 0) = rs.Fields("LastName")
ElseIf IsNull(rs.Fields("LastName")) Then
UPArray(icounter, 0) = ""
End If
If Not IsNull(rs.Fields("FirstName")) Then
UPArray(icounter, 1) = rs.Fields("FirstName")
ElseIf IsNull(rs.Fields("FirstName")) Then
UPArray(icounter, 1) = ""
End If
UPArray(icounter, 2) = rs.Fields("FullName")
'Debug.Print "items: "; icounter & " " & UPArray(icounter, 0) & " : " & UPArray(icounter, 1) & " : " & UPArray(icounter, 2)
icounter = icounter + 1
rs.MoveNext
Else
rs.MoveNext
End If
Loop
End If
Set rs = Nothing
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset, dbSeeChanges)
'updates providers
For i = 0 To rs.Fields.Count - 1 ' keeps loop in database fields
rs.MoveFirst
Do While Not rs.EOF
'Debug.Print rs.Fields(i).Value
For icounter = 0 To actrecords - 1
'If IsNull(rs.Fields(i).Value) Then
'rs.Fields(i).Value = "None Entered"
'End If
If Not IsNull(rs.Fields(i).Value) Then
If (InStr(1, rs.Fields(i).Value, UPArray(icounter, 0), 1) > 0 And InStr(1, rs.Fields(i).Value, UPArray(icounter, 1), 1) > 0) Then
rs.Edit
rs.Fields(i).Value = UPArray(icounter, 2)
rs.Update
End If
ElseIf IsNull(rs.Fields(i).Value) Or (InStr(1, rs.Fields(i).Value, "REFERRING NO", 1)) Then
rs.Edit
rs.Fields(i).Value = "No Entry"
rs.Update
End If
Next
rs.MoveNext
Loop
rs.MoveFirst
Next
Set rs = Nothing
Set db = Nothing
End Function
It works as intended, however whenever I run the function, I get an access notice/error in VBA stating that I cannot save changes to my code because I no longer have exclusive access.
This of course goes away when I close and reopen. This is a really annoying thing when I am tweaking the code. Also, if I run it via macro with all tables and vba closed it still does this error.
I have some more tweaking to do to move it to the live tables.
I have searched around the net and the only thing that comes up is that the currentdb function is causing some sort of lockup issue. But I don't know.
Any input is appreciated.