I have a form that has a subform in it. The subform gets populated by a query.
When you enter data into the form and click a button it is supposed to add it to the subform.
It works partially right now. It is refreshing the subform, but it is one click too late.
Example if you enter entry 1 nothing happens when you enter entry 2 the subform then shows entry 1.
The repaint sub routine is:
_______________ _______________ ___________
The whole form code is:
When you enter data into the form and click a button it is supposed to add it to the subform.
It works partially right now. It is refreshing the subform, but it is one click too late.
Example if you enter entry 1 nothing happens when you enter entry 2 the subform then shows entry 1.
The repaint sub routine is:
Code:
Private Sub UpdaterxQuery() [Form_Log Form].rxQuery.Requery [Form_Log Form].Repaint End Sub
The whole form code is:
Code:
Option Compare Database Public Sub clearForm() [Form_Log Form].aRxNumber.Value = "" [Form_Log Form].aQuantity.Value = "" [Form_Log Form].aDaySupply.Value = "" [Form_Log Form].cLoanedMed.Value = "" [Form_Log Form].aPatientName.Value = "" [Form_Log Form].aHomeName.Value = "" End Sub Public Sub aRxNumber_AfterUpdate() Dim patName, theHome, loggedBy As String Dim rxNum, patId, homeId, theQuantity, daySupply As Long Dim LoanedMeds As Boolean LoanedMeds = Val(Nz([Form_Log Form].cLoanedMed.Value, False)) [Form_Log Form].cLoanedMed.Value = False rxNum = Val(Nz([Form_Log Form].aRxNumber.Value, 0)) Dim sqlR, sqlP, sqlH, sqlD1, sqlD2, sqlD3, sqlL As DAO.Recordset Dim strDB, objDB strDB = CurrentProject.FullName Set objDB = OpenDatabase(strDB) Set sqlL = objDB.OpenRecordset("SELECT [UserID] FROM [USERLIST] WHERE [Logged In] = True") loggedBy = sqlL![UserID] Set sqlR = objDB.OpenRecordset("SELECT [PatientID] FROM [SCRIPTLIST] WHERE [RXID] = " & rxNum) If sqlR.EOF And sqlR.BOF Then Call clearForm a = MsgBox("The Rx Number you entered does not exist in the database. ", vbOKOnly, "Error") Set sqlR = Nothing Set objDB = Nothing Exit Sub End If patId = sqlR![PatientID] Set sqlP = objDB.OpenRecordset("SELECT [Patient], [HouseID] FROM [PATLIST] WHERE [PatientID] = " & patId) patName = sqlP![Patient] patName = Trim(Replace(patName, vbTab, " ")) [Form_Log Form].aPatientName.Value = patName homeId = sqlP![HouseID] Set sqlH = objDB.OpenRecordset("SELECT [Home] FROM [HOMELIST] WHERE [HouseID] = " & homeId) theHome = sqlH![Home] [Form_Log Form].aHomeName.Value = theHome End Sub Private Sub bLogItem_Click() theQuantity = Val(Nz([Form_Log Form].aQuantity.Value, 0)) daySupply = Val(Nz([Form_Log Form].aDaySupply.Value, 0)) LoanedMeds = Val(Nz([Form_Log Form].cLoanedMed.Value, False)) [Form_Log Form].cLoanedMed.Value = False rxNum = Val(Nz([Form_Log Form].aRxNumber.Value, 0)) If rxNum = 0 Or theQuantity = 0 Or daySupply = 0 Then a = MsgBox("Please enter a non-zero value for both the Rx Number, Day Supply and the Quantity.", vbOKOnly, "Error") Exit Sub End If Dim CurDate As Long CurDate = Date Dim strDB, objDB strDB = CurrentProject.FullName Set objDB = OpenDatabase(strDB) Set sqlL = objDB.OpenRecordset("SELECT [UserID] FROM [USERLIST] WHERE [Logged In] = True") loggedBy = sqlL![UserID] objDB.Execute "INSERT INTO [LOGLIST] (" & _ "[Log Date], [Rx Number], [Quantity], " & _ "[Day Supply], [Loaned Med?], [Logged By]) VALUES (" & _ CurDate & ", " & _ rxNum & ", " & _ theQuantity & ", " & _ daySupply & ", " & _ LoanedMeds & ", '" & _ loggedBy & "')" Call clearForm [Form_Log Form].aRxNumber.SetFocus Call UpdaterxQuery End Sub Private Sub UpdaterxQuery() [Form_Log Form].rxQuery.Requery [Form_Log Form].Repaint End Sub
Comment