Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Update and Dlookup

Posted on 2016-08-13
4
Medium Priority
?
49 Views
1 Endorsement
Last Modified: 2016-08-14
Hello experts,

I have a combo box (cboFacilityType) on a form (underlying table and field: tblDraws_Details.FacilityType) and after I update cboFacilityType I need to update another field in the same record (tblDraws_Details.ID_facility)  but I need to update to the same value where tblFacilityCommitments.FacilityType=tblDraws_Details.FacilityType)

I basically I need to update [tblDraws_Details.ID_facility] where [tblFacilityCommitments.FacilityType = tblDraws_Details.FacilityType

I think it would look something like this (but it it doesnt update to anything) :
FYI:  

Private Sub cboFacilityType_AfterUpdate()

    Me.ID_facility = DLookup("FacilityType", "tblFacility_Commitments", "FacilityType=" & [FacilityType].Value & "")
                                                                                                                                                     '   ^^^possibly facilitytype.column(1)-didnt work tho
End Sub

Possibly InsertInto would be another way to do this instead of dlookup because I believe Dlookup slows the db.
thank you
1
Comment
Question by:pdvsa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 total points
ID: 41755024
This:

    Me.ID_facility = DLookup("ID_facility", "tblFacility_Commitments", "FacilityType=" & Me.[cboFacilityType])

 Would be if the combo's bound field was FacilityType and it was numeric.  If a string, it would be this:

    Me.ID_facility = DLookup("ID_facility", "tblFacility_Commitments", "FacilityType='" & Me.[cboFacilityType] & "'")

or to be clearer:

    Me.ID_facility = DLookup("ID_facility", "tblFacility_Commitments", "FacilityType=" & chr$(34) & Me.[cboFacilityType] & chr$(34))

 Chr$(34) being the quote character.

 If FacilityType is something other than the combo's bound field, then you would use the column(X), but note that it is zero based.  So if it was the 2nd column in the combo's rowsource, then:

    Me.ID_facility = DLookup("ID_facility", "tblFacility_Commitments", "FacilityType=" & Me.[cboFacilityType].Column(1))

and note that I'm assuming ID_facility is the same in your lookup table.

Jim.
1
 

Author Comment

by:pdvsa
ID: 41755173
Thank you.  
your #1 worked:
Me.ID_facility = DLookup("ID_facility", "tblFacility_Commitments", "FacilityType=" & Me.[cboFacilityType])

I also modified your suggestion from column(1) to column (0) as the ID on the cbo is in the first column.  After I did this, it worked just as the above:
Me.ID_facility = DLookup("ID_facility", "tblFacility_Commitments", "FacilityType=" & Me.[cboFacilityType].Column(0))

thank you very much for your expert assistance.
0
 

Author Comment

by:pdvsa
ID: 41755174
Also, I have not used the site in over a year.  I use to award points.   I assume points are no longer awarded.  Let me know if I have missed something.
0
 
LVL 58
ID: 41755377
A lot has changed recently (just this week in fact), but points are still awarded,   Just mark my comment as best solution.

Jim.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question