Solved

Update and Dlookup

Posted on 2016-08-13
4
43 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
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 57
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

735 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