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

Auto Update Form Controls When Another Control is Updated

P: 13
I have a form I use to log in sample with the Lab ID as the tables primary key. Currently I have this form open to the last record for entering new samples. However if I type in or select an existing lab ID I would like the other feilds to auto populate with the data for the lab ID. I have tried a Find Record command button but that gives me an error.

Thanks for any help.
Jan 10 '14 #1

✓ answered by BikeToWork

Make a combo box with the LabID as the rowsource. Create a procedure for the after_update event on the combo. In the event have the form find the record based on the selection in the combo box. Something like this should work.
Expand|Select|Wrap|Line Numbers
  1. Dim RSClone As DAO.Recordset
  2. Dim lngLabID as Long
  3.  
  4. Set RSClone = Me.RecordsetClone
  5.  
  6. If IsNull(Me.cboSearchLabID) Then
  7.     Exit Sub
  8. End If
  9.  
  10. lngLabID= Me. cboSearchLabID
  11.  
  12. RSClone.FindFirst "[ID ]= " & lngLabID
  13. If RSClone.NoMatch = False Then
  14.     Me.Bookmark = RSClone.Bookmark
  15. End If
  16.  
  17. Set RSClone = Nothing
  18.  

Share this Question
Share on Google+
9 Replies


Rabbit
Expert Mod 10K+
P: 12,315
If Lab ID is supposed to be the unique primary key, how can you use an existing Lab ID? That's contradictory.
Jan 10 '14 #2

P: 13
I dont want to use an exsiting lab ID. But if I select an exsisting one I would like the other feilds to populate with the data for that one, for editing mistakes etc,.
Jan 10 '14 #3

100+
P: 124
It sounds like an unbound form. Is that the case? If the form is data-bound, the other fields should also populate when you go to an existing LabID.
Jan 10 '14 #4

P: 13
It does automatically populate the other feilds when I use the nav buttons, but this will not be feasible. I need to be able to type in and/or select the Lab ID and have it do it as well.
Jan 10 '14 #5

100+
P: 124
Make a combo box with the LabID as the rowsource. Create a procedure for the after_update event on the combo. In the event have the form find the record based on the selection in the combo box. Something like this should work.
Expand|Select|Wrap|Line Numbers
  1. Dim RSClone As DAO.Recordset
  2. Dim lngLabID as Long
  3.  
  4. Set RSClone = Me.RecordsetClone
  5.  
  6. If IsNull(Me.cboSearchLabID) Then
  7.     Exit Sub
  8. End If
  9.  
  10. lngLabID= Me. cboSearchLabID
  11.  
  12. RSClone.FindFirst "[ID ]= " & lngLabID
  13. If RSClone.NoMatch = False Then
  14.     Me.Bookmark = RSClone.Bookmark
  15. End If
  16.  
  17. Set RSClone = Nothing
  18.  
Jan 10 '14 #6

zmbd
Expert Mod 5K+
P: 5,287
blpierce76:
Hello there, as a chemist I have an idea as to what you might be wanting (^_^)

We need to make sure that your database is normalized. From what I've read so far it may not be, or is not normalized far enough.
Please read thru: > Database Normalization and Table Structures.
Jan 10 '14 #7

P: 13
Bike to Work,

That worked well, but is there a way now that if I enter a new LabID to have the rest of the form go blank, or to a new record?
Jan 10 '14 #8

P: 13
Thanks for that link zmbd.

But unlike you, this chemist may be outta his league with this database stuff. LOL.

Thanks for the help.
Jan 10 '14 #9

zmbd
Expert Mod 5K+
P: 5,287
Because we don't know the structure of the database and the form(s) you're using, the answer to your second question is - "more than likely yes."

However, we do try to keep to one topic per thread; thus, please start a new post (or search here on Bytes.com first (^_^) ) Please include a link back to this thread for context if needed.

As for
However, "this chemist may be outta his league" we're not out of your abilities.... there's the minors! ((^_^))

If you need help normalizing the database, please start a new thread. We don't mind helping thru the rough spots; thus, if you show your work, we can maybe provide some guidance to help with the design. I know that I occationally need that help when starting a new database... even if it's just to proof-read the schema!
Jan 11 '14 #10

Post your reply

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