VBA Code Works in Single Form but Gives Wrong Results in Continuous Form (6 Viewers)

Falcon88

Registered User.
Local time
Tomorrow, 00:27
Joined
Nov 4, 2014
Messages
321
I’m using the following VBA code in Access:

Private Sub xx Click()

Dim strWhere As String

strWhere = "[EmploeeID]=" & [FatherNo]

Debug.Print strWhere

DoCmd.OpenForm "frmEmploees", acNormal, strWhere

End Sub

When I use it on a button in a single form, it works correctly and opens the expected record.

However, when I use the same code in a continuous form, it gives incorrect results.


Note that the FatherNo field contains duplicate values.

I need this code to work in the continuous form as it’s very important for my application. Does anyone know a solution or workaround?
 
Where it me, I'd have the query you are using as your recordsource do the concatenation and have the result shown on the continuous form in a text box. Then, once you make sure everything is working, you can hide the text box. Don't delete it. Unless it is a value in a control on a continuous form the value you have is not reliable.
 
I’m using the following VBA code in Access:

Private Sub xx Click()

Dim strWhere As String

strWhere = "[EmploeeID]=" & [FatherNo]

Debug.Print strWhere

DoCmd.OpenForm "frmEmploees", acNormal, strWhere

End Sub

When I use it on a button in a single form, it works correctly and opens the expected record.

However, when I use the same code in a continuous form, it gives incorrect results.


Note that the FatherNo field contains duplicate values.

I need this code to work in the continuous form as it’s very important for my application. Does anyone know a solution or workaround?
The key to your problem is probably here: "Note that the FatherNo field contains duplicate values."

And your description of the problem is sufficiently ambiguous to suggest that possibly you are getting any one of those duplicate values back, not any specific one you might happen to want.

Or perhaps, you mean something else by "...incorrect results." If so, please be specific about:

What you want to happen.

What does actually happen.
 
The key to your problem is probably here: "Note that the FatherNo field contains duplicate values."

And your description of the problem is sufficiently ambiguous to suggest that possibly you are getting any one of those duplicate values back, not any specific one you might happen to want.

Or perhaps, you mean something else by "...incorrect results." If so, please be specific about:

What you want to happen.

What does actually happen.


I have a single form to display employee and family data, where each individual has a separate record. They are identified by the Father's Number (FatherNo), which holds the actual father’s data for the family.

I used a continuous form to display everyone's data and to search for any information. I applied the code mentioned earlier to a button in the details section, but it doesn't work correctly.

I created another single form, used the same code, and it opened the correct employee form exactly as I wanted.

My question is: Why doesn't the code work properly on the continuous form as I expect?
 

Users who are viewing this thread

Back
Top Bottom