Button opens form with specific data

bsnalex

Registered User.
Local time
Yesterday, 16:38
Joined
Feb 27, 2009
Messages
27
I've now tried this a few times with no luck--

you know how you add a button on a form that will open a further form. You can select "Find specific data to display". Well, when I selec that option (which I want to do) up comes the screen where you can match the criteria. I find that my "left" column (primary form) is completely blank, whereas the "right" column (popup form) has the full range of fields.

I have manually tried to add the criteria in VB using VB from a similar button and replacing the necessary and my code now looks like--
Code:
Private Sub Command124_Click()
On Error GoTo Err_Command124_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frm5YearAudit"
    
    stLinkCriteria = "[Unit Number]=" & Me![NUMBER]
    DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_Command124_Click:
    Exit Sub
Err_Command124_Click:
    MsgBox Err.Description
    Resume Exit_Command122_Click
    
End Sub

Problem is now, even after I've manually added the code when I push the button in Form view, the link criteria doesn't work and the popup form simply goes to the first record rather than filtering on the criteria.

For info: "Unit Number" is the field on my primary form that contains patient hospital details and "NUMBER" is the related field in the popup form that contains certain dental data from the dental table.

Can anyone tell me why - A) the column is blank when selecting link criteria and B) after I've added the VB, why it still doesn't work?

I've tried deleting the button and starting over and the same results every time.

Thanks in advance for any help.
 
Me refers to the current form, as I understand your explanation it sounds like your looking for:
stLinkCriteria = "[NUMBER]=" & Me![Unit Number]

From the current (primary) form use [Unit number] to find the [number] (note no Me) on the sub/popup form.

FYI1: You should really not use spaces or any special characters in Column names anywhere, this will cause problems in the future.

FYI2: I hope your not leaving the controls as Command124, but instead give them a more usefull/meaning full name

FYI3: stLinkCriteria = "[Unit Number]=" & Me![NUMBER] will work for numbers,
Text: stLinkCriteria = "[Unit Number]='" & Me![NUMBER] & "'"
Date: stLinkCriteria = "[Unit Number]=#" & Me![NUMBER] & "#"

FYI4: If your using dates, make sure that the date being entered is in US (MM/DD/YYYY)or ISO (YYYY-MM-DD) format, euro format will break.

Edit: Seems like I 'beat' JNR by a few seconds, him having the same idea.
 
"Unit Number" is the field on my primary form that contains patient hospital details and "NUMBER" is the related field in the popup form that contains certain dental data from the dental table.

stLinkCriteria = "[Unit Number]=" & Me![NUMBER]

I think you got the stLinkCriteria backwards.

Code:
stLinkCriteria = "[Number]=" & Me.[Unit Number]

JR
 
Bsnalex,

If Unit Number is the field on your primary form, and NUMBER is the related field in the popup form, then:
"[Unit Number]=" & Me![NUMBER]
... is backwards. It should be:
"[NUMBER]=" & Me![Unit Number]

Oh, and please note, this is VBA, not VB.
 

Users who are viewing this thread

Back
Top Bottom