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
Solved

Comparing user entered value to table value

Posted on 2011-09-08
5
483 Views
Last Modified: 2013-11-24
Hi,

How are you?

I have a table with 2 columns.
1st column contains cities and 2nd column contains provinces.

I want to store the province in a string called 'province' if the user entered city exists in the city column. I have the following code but not so familier with combining sql with vba.

Dim origin As String
Dim province as String
Dim rs As Recordset
 
origin = ocitytxt

I do want a sql formula which will find out the relative province based on city name and assign the province to province string

Something like this formula but I copied this from another example here...I know this is wrong :(

province = CurrentDb.OpenRecordset("SELECT origin FROM table1 WHERE (((city)=origin()));")

Thanks a million!
0
Comment
Question by:Shanan212
  • 3
  • 2
5 Comments
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 250 total points
ID: 36504549
<How are you?>
Fine, thanks for asking...
;-)

Though I am a bit hazy on what your one distinct question is here, ...it seems to be rooted in the concept of "Cascading Lists"

So see here as a start:
http://www.fontstuff.com/access/acctut10.htm
http://www.candace-tripp.net/download/combopopulate2007.zip
http://www.candace-tripp.net/download/cascadecombo2k.zip
http://www.candace-tripp.net/download/2table_cascadecombo2k.zip


;-)

JeffCoachman
0
 
LVL 13

Author Comment

by:Shanan212
ID: 36504852
Thank you for your answer

Based on examples you gave and online research, I came up with this for initial part

OUT - Table
OUTCOMBI - Column
Origin is defined as "Origin = text1" (it contains value from text box)

        strSQL = "SELECT * FROM [b]OUT[/b] WHERE [b]OUTCOMBI[/b] = [b]origin[/b]"
        Set rst = CurrentDb.OpenRecordset(strSQL)
        
        If Not (rst.EOF And rst.BOF) Then
            varResult = rst!MyData
        End If
        
        MsgBox varResult
        
        Set rst = Nothing

Open in new window


So the above is expected to output the same 'origin' value if its found among the table.

How ever, I am getting "Too few parameters, expected 1" error on line

     Set rst = CurrentDb.OpenRecordset(strSQL)
-------

If the above problem is solved, then I can design a boolean function to see if the value exists - returning a yes/no. However, for the 2nd part, how do I get the corresponding column value from the 'OUT' table

I've done my fair share of learning via http://www.w3schools.com/sql/sql_orderby.asp 
But nothing exists in terms of assigning the corresponding column value to a predefined value called 'xVal'

say 'Dim xVal as String'
0
 
LVL 13

Author Comment

by:Shanan212
ID: 36505004
NVM I found out :p

I used this finally

        strSQL = "Select OUT.TCOMBI " & "FROM OUT " & "WHERE OUT.OUTCOMBI = '" & origin & "' " '& "ORDER BY tblAll.City;"
        Set rst = CurrentDb.OpenRecordset(strSQL)
        
        If Not (rst.EOF And rst.BOF) Then
            varResult = DLookup("TCOMBI", "OUT")
        End If
        
        MsgBox varResult
        
        Set rst = Nothing

Open in new window

0
 
LVL 13

Author Closing Comment

by:Shanan212
ID: 36505065
Thanks for the guides
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36506290
Thanks,

But you must also give yourself some credit.
You have shown here that you are able to take basic theory and apply it to work in your specific application, ...all with no hand-holding!

;-)

JeffCoachman
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

856 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