?
Solved

Adding & Subtracting Recordsets using string

Posted on 2007-04-11
5
Medium Priority
?
372 Views
Last Modified: 2012-05-05
I have created some recordsets that hold information.
I now need to add (or subtract) values in the recordsets dependent on values in a particular field.
I am getting a runtime error.
The following is my code:

strGLMTH = "rst2e.Fields('GLmth').Value"

If rst2d.Fields("SourceSystem").Value = "SYS" Then
strGLMTH = strGLMTH & " + rst2d.Fields('GLmth').Value"
Else
strGLMTH = strGLMTH & " - rst2d.Fields('GLmth').Value"
End If

If rst2c.Fields("SourceSystem").Value = "SYS" Then
strGLMTH = strGLMTH & " + rst2c.Fields('GLmth').Value"
Else
strGLMTH = strGLMTH & " - rst2c.Fields('GLmth').Value"
End If

If rst2b.Fields("SourceSystem").Value = "SYS" Then
strGLMTH = strGLMTH & " + rst2b.Fields('GLmth').Value"
Else
strGLMTH = strGLMTH & " - rst2b.Fields('GLmth').Value"
End If

If rst2a.Fields("SourceSystem").Value = "SYS" Then
strGLMTH = strGLMTH & " + rst2a.Fields('GLmth').Value"
Else
strGLMTH = strGLMTH & " - rst2a.Fields('GLmth').Value"
End If
MsgBox strGLMTH

rstZFPR.Fields("GLmth").Value = strGLMTH

Is there a way I can get Access (VB) to do the resultant equation that the string (strGLMTH) compiles?
FYI The message box gives the correct string.

Any help would be great
:-)
0
Comment
Question by:martywal
  • 2
  • 2
5 Comments
 
LVL 54

Accepted Solution

by:
Ryan Chong earned 700 total points
ID: 18888350
try this..


strGLMTH = val(rst2e.Fields('GLmth').Value)

If rst2d.Fields("SourceSystem").Value = "SYS" Then
strGLMTH = strGLMTH  + val(rst2d.Fields('GLmth').Value)
Else
strGLMTH = strGLMTH - val(rst2d.Fields('GLmth').Value)
End If

If rst2c.Fields("SourceSystem").Value = "SYS" Then
strGLMTH = strGLMTH + val(rst2c.Fields('GLmth').Value)
Else
strGLMTH = strGLMTH  - val(rst2c.Fields('GLmth').Value)
End If

If rst2b.Fields("SourceSystem").Value = "SYS" Then
strGLMTH = strGLMTH + val(rst2b.Fields('GLmth').Value)
Else
strGLMTH = strGLMTH  - val(rst2b.Fields('GLmth').Value)
End If

If rst2a.Fields("SourceSystem").Value = "SYS" Then
strGLMTH = strGLMTH + val(rst2a.Fields('GLmth').Value)
Else
strGLMTH = strGLMTH  - val(rst2a.Fields('GLmth').Value)
End If
MsgBox strGLMTH

rstZFPR.Fields("GLmth").Value = strGLMTH
0
 
LVL 54

Assisted Solution

by:Ryan Chong
Ryan Chong earned 700 total points
ID: 18888456
you may try use " instead of ' , like:


strGLMTH = val(rst2e.Fields("GLmth").Value)

If rst2d.Fields("SourceSystem").Value = "SYS" Then
strGLMTH = strGLMTH  + val(rst2d.Fields("GLmth").Value)
Else
strGLMTH = strGLMTH - val(rst2d.Fields("GLmth").Value)
End If

If rst2c.Fields("SourceSystem").Value = "SYS" Then
strGLMTH = strGLMTH + val(rst2c.Fields("GLmth").Value)
Else
strGLMTH = strGLMTH  - val(rst2c.Fields("GLmth").Value)
End If

If rst2b.Fields("SourceSystem").Value = "SYS" Then
strGLMTH = strGLMTH + val(rst2b.Fields("GLmth").Value)
Else
strGLMTH = strGLMTH  - val(rst2b.Fields("GLmth").Value)
End If

If rst2a.Fields("SourceSystem").Value = "SYS" Then
strGLMTH = strGLMTH + val(rst2a.Fields("GLmth").Value)
Else
strGLMTH = strGLMTH  - val(rst2a.Fields("GLmth").Value)
End If
MsgBox strGLMTH

rstZFPR.Fields("GLmth").Value = strGLMTH
0
 
LVL 14

Assisted Solution

by:bluelizard
bluelizard earned 300 total points
ID: 18888516
use the eval function: for example:

  Eval("1 + 1")

returns 2.


--bluelizard
0
 

Author Comment

by:martywal
ID: 18897665
Sorry Guys,
Forgot I'd posted this.
I ended up not using a string as I couldn't get it to work.
It looked like this:

rstZFPR.Fields("GLmth").Value = rst2e.Fields("GLmth").Value

If rst2d.Fields("SourceSystem").Value = "SYS" Then
rstZFPR.Fields("GLmth").Value = rstZFPR.Fields("GLmth").Value + rst2d.Fields("GLmth").Value
Else
rstZFPR.Fields("GLmth").Value = rstZFPR.Fields("GLmth").Value - rst2d.Fields("GLmth").Value
End If

If rst2c.Fields("SourceSystem").Value = "SYS" Then
rstZFPR.Fields("GLmth").Value = rstZFPR.Fields("GLmth").Value + rst2c.Fields("GLmth").Value
Else
rstZFPR.Fields("GLmth").Value = rstZFPR.Fields("GLmth").Value - rst2c.Fields("GLmth").Value
End If

If rst2b.Fields("SourceSystem").Value = "SYS" Then
rstZFPR.Fields("GLmth").Value = rstZFPR.Fields("GLmth").Value + rst2b.Fields("GLmth").Value
Else
rstZFPR.Fields("GLmth").Value = rstZFPR.Fields("GLmth").Value - rst2b.Fields("GLmth").Value
End If

If rst2a.Fields("SourceSystem").Value = "SYS" Then
rstZFPR.Fields("GLmth").Value = rstZFPR.Fields("GLmth").Value + rst2a.Fields("GLmth").Value
Else
rstZFPR.Fields("GLmth").Value = rstZFPR.Fields("GLmth").Value - rst2a.Fields("GLmth").Value
End If

Will split points
0
 

Author Comment

by:martywal
ID: 18897678
I ended up finding that could add recordsets using a string such as this.
THanks for help
Martywal
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

807 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