?
Solved

Update and Dlookup

Posted on 2016-08-13
4
Medium Priority
?
48 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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

762 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