Combobox opens a different form

fabrizio19

Registered User.
Local time
Today, 05:13
Joined
Aug 9, 2012
Messages
75
Combobox opens a different form with criteria inserted in the combobox

Hi everyone.
I have the following problem:
I have a form with a combobox.From this combobox I would like to trigger the openened of a different form with the name and surname of the patients selected into the combobox.
I used this vba code

Private Sub Find_Click()

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "ID Patient"
stLinkCriteria = "[PTS]=" & Me.Identification

If IsNull(Me.Identification) Then
MsgBox "Put the name in the combobox", vbCritical, "Attenzione!"

Else
DoCmd.OpenForm stDocName, , , stLinkCriteria


End If
End Sub
The problem is that when the form Id patient is already opened every thing works fine but when the Id patient form is not opened it looks like if the combobox was not able to trigger the form with the name and surname of the patients!
Why it happens?
Thanks in advance
Fabrizio
 
Last edited:
If [PTS] is a string (text) value then it should be:
stLinkCriteria = "[PTS]='" & Me.Identification & "'"
 
Thamk you for yoyr quick reply.
pts is a number not a text
yours
f
 
Add this line:
MsgBox "Criteria = [" & stLinkCriteria & "]"
DoCmd.OpenForm stDocName, , , stLinkCriteria
...and see what happens.
 
The Msgbox gives to me the right number but the form opened (triggered by the combobox) doesn't give to me the right patients.
 

Attachments

Last edited:
Does the 2nd form display the [PTS] value? Is it wrong?
 
The problem is that the second form instead of getting back the record with the patient's number (selected by combobox in the form menu) give back a blank form.However if the form is already opened every thing works well.
 
Thats because you open de form in append mode, change the openform line to:
Code:
DoCmd.OpenForm stDocName, , , stLinkCriteria[COLOR="Red"][B], acFormEdit[/B][/COLOR]
 

Users who are viewing this thread

Back
Top Bottom