By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,345 Members | 2,404 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,345 IT Pros & Developers. It's quick & easy.

List Box Value

benchpolo
100+
P: 142
I have a form that contains client information such as client id, name, address etc. etc.

Then I have another form which is a list box that contains the client id and name.

What Iím trying to accomplish is that when I click a client id in the list box the form will load the detailed information of the client id that I choose from the list box.

List Box (lclient) code
Private Sub lclient_Click()
'assign value to global variable
gClientID = lclient
'load form
Dim sform As String
sform = "W7"
DoCmd.OpenForm sform, , , , acFormEdit
End Sub

Form Load Code
Private Sub Form_Load()
clientid.setfocus
clientid = gClientID
End Sub

PROBLEM: When the form loads itís only changing the value of the clientid field the rest of the data are not.

Please advise.

Thanks.
Mar 17 '08 #1
Share this Question
Share on Google+
4 Replies


FishVal
Expert 2.5K+
P: 2,653
Why not just filter the opened form by [clientid]?
Mar 17 '08 #2

benchpolo
100+
P: 142
That is not the spec of the project.

A list box with the list of client refencing client id so when a user selects the client id another form will load and displays the client information based on the selected client id.

Thanks.
Mar 18 '08 #3

FishVal
Expert 2.5K+
P: 2,653
That is not the spec of the project.

A list box with the list of client refencing client id so when a user selects the client id another form will load and displays the client information based on the selected client id.

Thanks.
And the form opened has, let us say, [Clients] table as recordsource where [clientid] I guess is a PK field. So my "question" remains the same - why not just filter the form to display a single record where [clientid] is that selected with the listbox?

If I'm getting something wrong, then please provide a clearer explanation of your situation.

Kind regards,
Fish
Mar 18 '08 #4

missinglinq
Expert 2.5K+
P: 3,532
What you're missing, Fish, is

"That is not the spec of the project."

Since business people usually tell programmers what to do, not how to do it, I suspect that the person setting the "spec of the project" is a classroom instructor.

You need to dump the global variable approach, as well as the Form_Load code and look at the fourth argument (WhereCondition) of OpenForm. The standard approach to this problem would be something like this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub lClient_Click()
  2.  Dim sform As String
  3.  sform = "W7"
  4.    DoCmd.OpenForm sform, , , "[ClientID] = '" & Me.lClient & "'", acFormEdit
  5. End Sub
  6.  
Mar 18 '08 #5

Post your reply

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