I have a form with a subform. The form has values that add a record to a table. The subform is populated by a query that draws from the table. I need the subform to update when you add a new record.
The problem that I'm having is that, when I open the form, the first added record won't show up on the subform. On the second entry it shows the first and second records.
How do I get the refresh/repaint method to work for the first entry? - 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, 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
-
Set sqlL = Nothing
-
Set sqlR = Nothing
-
Set sqlP = Nothing
-
Set sqlH = Nothing
-
Set objDB = Nothing
-
-
-
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 & "')"
-
-
Set sqlL = Nothing
-
Set objDB = Nothing
-
-
Call clearForm
-
Call UpdaterxQuery
-
[Form_Log Form].aRxNumber.SetFocus
-
-
End Sub
-
-
Private Sub UpdaterxQuery()
-
[Form_Log Form].rxQuery.Requery
-
[Form_Log Form].Repaint
-
-
End Sub
-
-
Private Sub Form_Load()
-
[Form_Log Form].aRxNumber.InputMask = "000000;; :"
-
-
End Sub
-
1 1449 zmbd 5,501
Expert Mod 4TB
JmShipe:
It sounds as if your parent/child links are not setup correctly. If there are related records when you first open the form, then these should show in the subform. However, from what information you've given it is difficult to tell.
You may find the following useful: Form-Subform Filtering
By looking over Neopa's tutorial it may give you some leads with your issue.
-z
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Richard L Rosenheim |
last post by:
I'm trying to create a style sheet to generate HTML output, based upon some
XML data.
I'm grouping some data, and I'm trying to get the very first entry either
just passed as a parameter, or...
|
by: Paul H |
last post by:
Hi
I have a problem with certain users of my ASP.NET application. The user logs
into the site, and they are logged into the application. Then when they
select a link, they are presented with a...
|
by: christophe.leroquais |
last post by:
Hi,
I have a HashTable that can have the same keys.
For example:
Key: myKey1, myKey2, myKey3, myKey1
Value: "value1" , "value2" , "value3", "value4"
That's ok and I'm happy with that....
|
by: bosmatthews |
last post by:
I have a main form with a subform and a second subform nested to the first subform. The data entry property for all three forms (main, subform and sub-subform) is set to "yes" because I am intending...
|
by: Presto |
last post by:
I have a Main form with a subform named Payments.
I have a button on the main form named NewPaymentEntry that opens a small
popup form to enter a new payment.
There is a "Save" , "Cancel", and...
|
by: TheSmileyCoder |
last post by:
I have a subform "frm_Obs" on my main form "frm_Main"
If there is no records, I want the user to be able to add one. If there allready is one, I want the user to be able to change it, but not add...
|
by: bbobely |
last post by:
Hi,
I've built a sequence that works thusly:
User chooses a value from a combo box. This causes a query to run displaying records with a field value matching the combo box in subform 1. Then, the...
|
by: Syed Khaleel Ahamed |
last post by:
Dear sir,
I am doing a project of employee attendance management system using jsp, servlets. In that project it will capture the date and time of that employee when he entered...
|
by: cambar |
last post by:
When Access db is first opened and the first record is entered, tabbing on subform works properly. However, when subsequent records are entered, the subform retains memory of the last field filled in...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |