473,396 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Trying to evaluate a simple Dlookup without success

What I am trying to do is on the click event of "Command167", run a Dlookup on the number that was just typed into "cboMoveTo1" and find the value located in the table "tblName" in the "Open/Closed" field.

The Dlookup seems to work fine on its own. I tested it with a text box that was set to:

Expand|Select|Wrap|Line Numbers
  1. = DLookup("[Open/Closed]", "[tblName]", "[cboMoveTo1] = " & [Forms]![Master]![cboMoveTo1])
and it would bring back the correct data.

Then what I need it to do is check to see if the Dlookup return equals "Locked" (from the "Open/Closed" field and if it does, display the message box only (without going to that record).

If the Dlookup returns anything other than "Locked", it will go onto the Recorset and bring up the old record for editing.

Here is the code I have that doesn't seem to work:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command167_Click()
  2.  
  3. Dim varX As Variant
  4. varX = DLookup("[Open/Closed]", "[tblName]", "[cboMoveTo1] = " & [Forms]![Master]![cboMoveTo1])
  5.  
  6. If varX = "Locked" Then
  7. MsgBox "This reference # is currently being edited by another user.  Please choose another Reference #!"
  8. Else
  9.  
  10.  
  11. Dim rs As DAO.Recordset
  12.  
  13.     If Not IsNull(Me.cboMoveTo1) Then
  14.         'Save before move.
  15.         If Me.Dirty Then
  16.             Me.Dirty = False
  17.         End If
  18.         'Search in the clone set.
  19.         Set rs = Me.RecordsetClone
  20.         rs.FindFirst "[Reference #] = " & Me.cboMoveTo1
  21.         If rs.NoMatch Then
  22.             MsgBox "Reference # not found. Please re-enter."
  23.         Else
  24.                     'Display the found record in the form.
  25.             Me.Bookmark = rs.Bookmark
  26.         End If
  27.         End If
  28.         End If
  29.         Set rs = Nothing
  30.         Set varX = Nothing
  31.  
  32. End Sub
Seems simple enough, but no matter what I do, it won't work. I am brand new at this so I really shouldn't say it looks simple because it's all new, but I'm learning.
Jan 9 '10 #1

✓ answered by nico5038

After you've selected a table (e.g. tblName) you can click the [...] button at the end of the property line.
Now Access will ask or you want to make a query and you accept that.
Now you can choose the fields needed (Like ID, Name and OpenClose) and close the query (accept the proposed "save").

When you do this for an existing combo box you'll need to switch from the Data tab to the Format tab to increment the number of rows into 3 and to set the width of the first and last column to 0, just leaving the name visible with a real width value.

Referring to the columns in VBA goes "zero-based", this the ID will be:
comboboxname.column(0), the Name column(1) and the OpenClose column(2).

Getting the idea ?

Nic;o)

7 2043
Sorry, I forgot to mention I am working in Access 2003.

Thanks
Jan 9 '10 #2
nico5038
3,080 Expert 2GB
You don't need the [Open/Closed] lookup, when you add the field to the combo's rowsource. Just make sure the number of columns (under the format tab of the properties window) is incremented by 1 and set the column widths correctly, setting the [Open/Closed] column to a width 0 (=invisible).
Now after the combo has been updated you can use comboname.column(2) (when it's the third colmn) to get the value for the [Open/Closed] field.
You could even show the field to the user, so (s)he knows or (s)he can update the selected row.

Nic;o)
Jan 10 '10 #3
Thank you for your reply! Not to sound like a complete idiot, but how do I make the number of columns increment? And in the rowsource of the combobox, it only gives me a list of all the tables I have (no individual fileds). Can I type in "Open/Closed" and have it work?

Could you give an example of the codes?

Thanks again and I apologize for my confusion!!!
Jan 10 '10 #4
nico5038
3,080 Expert 2GB
After you've selected a table (e.g. tblName) you can click the [...] button at the end of the property line.
Now Access will ask or you want to make a query and you accept that.
Now you can choose the fields needed (Like ID, Name and OpenClose) and close the query (accept the proposed "save").

When you do this for an existing combo box you'll need to switch from the Data tab to the Format tab to increment the number of rows into 3 and to set the width of the first and last column to 0, just leaving the name visible with a real width value.

Referring to the columns in VBA goes "zero-based", this the ID will be:
comboboxname.column(0), the Name column(1) and the OpenClose column(2).

Getting the idea ?

Nic;o)
Jan 10 '10 #5
Let me tell you something......I've posted this question on 3 different websites and received a total of 149 "views"! You are the only one that posted anything, and it WORKS!!!! I apologize for asking stupid questions by the way! After you walked me through it, I remembered I had done that 100's of times before! I didn't know about the Comboboxname.column(1) before though and that's what did it in the end!!!!

You have no idea how much I appreciate your help and I can't thank you enough!!
Jan 10 '10 #6
nico5038
3,080 Expert 2GB
Welcome to bytes.com !

I have a motto "There are no stupid questions, it's only stupid not to ask" :-)

Glad it's "fixed" and knowing that someone has gained some new knowledge is my greatest reward.

Nic;o)
Jan 10 '10 #7
MMcCarthy
14,534 Expert Mod 8TB
I have a motto "There are no stupid questions, it's only stupid not to ask" :-)
I second that motto :D
Jan 11 '10 #8

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

Similar topics

5
by: Steve | last post by:
Hello, I've been a PHP programmer for a number of years and have just started to learn JS. My Employer (a water analysis lab) wants what should be a very simple .js written that basically takes...
1
by: John Hargrove | last post by:
I am building a database to manage test samples in an environmental laboratory. I am learning Access as I go and don't know much about the programming aspects. I hope to make the application...
1
by: MUHAMAMD SALIM SHAHZAD | last post by:
dear sir, i would like to get your assitance about the above issues, can't find any better slutions or codes - table name: MOTOR2000 - field name1: POLICYNO - field name2: ExPolicyNo i...
2
by: chris.thompson13 | last post by:
I am having a problem setting the criteria part of the DLookup method correctly and am consequently getting an error message. I have a database of staff duties, part of which is a query (qryDaily)...
4
by: Tess2819 | last post by:
Hi Everyone, This is my first topic so I hope you can help. I have searched but can't seem to find what I am looking for, so here it is. I want to create a query using design view in...
1
by: Lee | last post by:
I have an orders form which has orderID as the primary key, it also has supplierID as a foreign key located on the form. I need a lookup field (that looks up the account number which is located in...
7
by: | last post by:
There are assorted "SQL Injection vulnerability assessment tools" out there. They scan your site and send your report. They also take your money. We don't have the money so I was wondering if I...
2
by: John | last post by:
To prevent the null-error from showing up when dlookup returns false I created the code beneath which doesn't seem very elegant. How can I code this without having to use the dlookup twice? If...
2
by: Denise | last post by:
Front end is Access 2002, back end is linked Oracle tables. My users need to describe things in feet and inches and want to use the standard ' and " abbrevations. On a testing form I go to a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.