DLookUp in VB6

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • consequence
    New Member
    • Feb 2007
    • 2

    DLookUp in VB6

    Hello, I'm a newbie at vb6 programming, I seem to have gotten stuck at a problem I can't resolve for several days now.

    I'm developing a payroll system using vb6 as front end and Access 2003 as back end. I have a label in my form, let's call it lblA. This label is supposed to be a numeric value, determined by another value in the same form, let's call it curA.

    In my Access tables, I have one called tblA, which has 3 columns, Range1, Range2 and Value. My curA falls between Range1 and Range2, which in turn will yield Value. This Value will be shown in lblA.

    Thus, if curA=2000, it'll be somewhere between R1=1900 and R2=2300 (let's say) and Value=25. My lblA is supposed to show 25.

    I've attempted to use SQL to accomplish my task, i.e. strSQL="SELECT * FROM tblA WHERE Range1<=curA<=R ange2"
    lblA=rec1!Value

    But it doesn't work. I've tried tinkering around with lots of variations, among them assigning the curA as string before passing it down to the SQL...but nothing seems to work. Recently I discovered this DLookUp function, but I am in doubts as to whether it could incorporate the BETWEEN...AND operacors...

    Any help would be greatly appreciated.
  • consequence
    New Member
    • Feb 2007
    • 2

    #2
    All right, I seem to have solved the problem by using this syntax:

    strSQL = DLookup("[Field in table I want value returned]", "tblA", "[Range2] >= " & [curA])

    lblA.Caption = strSQL

    Don't even have to use BETWEEN...AND concept because Access returns the first value that satisfies the [Range2]>=[curA] criterion...

    Now I have to figure out another problem which I think can be resolved through DLookup, but no idea yet...this one is fundamentally similar to the one above, but with several twists:

    1. It has to pass several arguments: If status A= 1, then it's straightforward ...just look at the two ranges, R1 and R2, and if curB falls between these two ranges, the value returned will be put in lblB...

    2. If status A=2 (there are only 2 status A's), then it has to pass status B which has also two statuses, i.e. status B=1 and status B=2...

    3. For both status B's (=1 and =2) there are, for EACH STATUS B, 10 (TEN!!) more conditions (assume it's called status C)...

    4. So for Status B=1 and Status B=2, the following condition must be status C=1, C=2, C=3, C=4...til C=10 for both status B's...every status B has a different set of status B's...

    Any ideas are greatly appreciated. It's complex because it's related to the Personal Tax Contribution in my country.

    Regards

    Comment

    Working...