Solved

Update and Dlookup

Posted on 2016-08-13
4
31 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
  • 2
  • 2
4 Comments
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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 57

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now