473,385 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Filter sub form from the main form.

I'm creatig a data base and in my front page i have 3 sub forms and 3 buttons for the sub forms to activate or not.

1. Subform1 is where all the current list of the patients being admitted for consultation. This form is Visible=True upon Form_Load().

2. Subform2 is where all the list of patient's name. This form is Visible=False upon Form_Load().

3. Subform3 displays the patient's personal information and the result entries (it is where the doctor encode their diagnosis, medications and laboratories). This form is Visible=False upon Form_Load().


I want to select a patient from subform1 linking the PatientID from the main form using the button3 and view it as a me.subform3.visible=True and me.subform1.Visible=False.

I have 2 option codes

First code : My problem on this code is that it will not work and no error messages.

Private Sub button3_Click()

Me.subform3.Visible = True
Dim varWhere As Variant

' Initialize to Null
varWhere = Null

' If specified a company name value
If Not IsNothing(Me.PatientID) Then
' .. build the predicate
varWhere = "[PatientID] LIKE '" & Me.PatientID & "*'"
End If

' Check to see that we built a filter
If IsNothing(varWhere) Then
MsgBox "Please select a patient.", vbInformation, gstrAppTitle
Exit Sub
End If

' See if any rows with a quick DLookup
If IsNothing(DLookup("PatientID", "Subform3Qry", varWhere)) Then
MsgBox "No Patient's last name meet your criteria.", vbInformation, gstrAppTitle
Exit Sub
End If

Me.Subform3.Controls("PatientID") = varWhere

End Sub

Second Code: but if im going to use this, it will display an error saying "Run time error '2185': you connot reference aproperty or method for a control unless the control has the focus."

Private Sub button3_Click()
Me.subform3.Visible = True

Dim temp As String
temp = "*" & PatientID.Text & "*"
Me.subform3.Form.Filter = "PatientID like '" & temp & "'"
Me.subform3.Form.FilterOn = True
End Sub

thanks alot in advance for helping.
Jul 5 '09 #1
6 2484
ADezii
8,834 Expert 8TB
@mjworks2009
  1. First Code - try a change in syntax:
    Expand|Select|Wrap|Line Numbers
    1. Dim strWhere As String
    2.  
    3. Me![subform3].Visible = True
    4.  
    5.  
    6. ' Initialize to Empty if you so desire
    7. strWhere = ""
    8.  
    9. ' If specified a company name value
    10. If Not IsNull(Me![PatientID]) Then
    11.   ' .. build the predicate
    12.   strWhere = "[PatientID] LIKE '" & Me![PatientID] & "*'"
    13. End If
    14.  
    15. ' Check to see that we built a filter
    16. If strWhere <> "" Then
    17.   MsgBox "Please select a patient.", vbInformation, gstrAppTitle
    18.     Exit Sub
    19. End If
    20.  
    21. ' See if any rows with a quick DLookup
    22. If IsNull(DLookup("[PatientID]", "Subform3Qry", strWhere)) Then
    23.   MsgBox "No Patient's last name meet your criteria.", vbInformation, gstrAppTitle
    24. End If
  2. Second Code, try a slight modification since the Text Property can only be referenced when the associated Control has the Focus.
    Expand|Select|Wrap|Line Numbers
    1. temp = "*" & Me![PatientID] & "*"
Jul 5 '09 #2
Tanks alot for the advice.. :)
Jul 5 '09 #3
ADezii
8,834 Expert 8TB
@mjworks2009
You are quite welcome. Just noticed that Line #16 should be:
Expand|Select|Wrap|Line Numbers
  1. If strWhere = "" Then 
Jul 5 '09 #4
Oh thank you so much. i will try this one.
Jul 5 '09 #5
wow... thank you once again for helping me. it did work.

best regards.
Jul 6 '09 #6
ADezii
8,834 Expert 8TB
@mjworks2009
You are quite welcome, myworks2009.
Jul 6 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Robert Neville | last post by:
I would like to add filter functionality to my database whether through the Main form or the subform. This question may be rudimentary, yet I have not less experience with filtering data outside...
2
by: Andante.in.Blue | last post by:
Hi everyone! I was wondering if there is a away to use Access 97's build in filter-by-form function but restrict its effect to just the subform. I have a parent form that shows the major...
7
by: damjanu | last post by:
Hi All; I need little help. I have a datasheet form. I allow user to do 'filter by selection'. My form contains a column with values. As user changes selections, I want to calculate totals....
3
by: Tony Williams | last post by:
Sorry to repost but I cannot work this out. Can anyone come up with a suggestion? I have a main form based on Table1. The form has a tab control of three pages. Each page has a subform based on a...
2
by: cefrancke | last post by:
I have a form (no underlying record set) that has two separate sub-forms on it. Each sub-form has data from two different tables. Above each sub-form there is one unbound combo box with a SQL...
3
by: dhowell | last post by:
In reading some of the posts on this group, it appears as though it is not strait forward at all to filter a form, which has subforms, by criteria which are either on subforms or span more than one...
8
by: Abedin | last post by:
I have 9 digits in form of "111020402". Then I have another 9 digits in form of "111020403". I have 100,000 records of these two 9-digit numbers. I want to filter this as follows: District:...
1
by: Bface | last post by:
Hi All, I am stuck on a problem and hope someone can help me out. I have 8 users who will be using a form . For the users to access their accounts I use the SendKeys function, the user click on...
0
by: diogenes | last post by:
"Rick Brandt" <rickbrandt2@hotmail.comwrote in news:bPnKj.456$%41.325 @nlpi064.nbdc.sbc.com: I used this approach, and it works a treat! ID In(SELECT Order_ID FROM orderitems WHERE NAME =...
1
by: woodey2002 | last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on. My databse mostly includes...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.