How do I code this in Vba?

  • Thread starter Thread starter Jen
  • Start date Start date
J

Jen

In Excel I retrieve a value in to the code (from a excel cell) like this:
"amount = CDbl(Worksheets("Sheet1").Range("A1").Value)"

How do I write this for an Access report, retrieving the value from a
textbox called "text_amount"?

Jen
 
How you do it will depend to some extent on what you want to do with it once you have it.
However, to retrieve this value in a module behind the report and assuming the textbox you
are referring to is on the report:

dblAmount = CDbl(Me.text_amount.Value)
 
Thanks for your help.

Would I put this (and the rest of the code) in the OnOpen event in the
report?

Also, how do I code the following (that is how to get the result from the
code to a specified textbox)

when in excel writing the output to cell A10:

If res <> "" Then
Worksheets("Sheet1").Range("A10").Select

Dim fontLONG As Long, font As String
fontLONG = BCL_getFont(handle)
font = BCL_convertStringToBSTR(fontLONG, -1)
Dim fontSize As Integer
fontSize = BCL_getHeight(handle, 11.3)
Selection.font.Name = font
Selection.font.Size = fontSize
Selection.Value = res
Else
Dim errLONG As Long, err As String
errLONG = BCL_getError(handle)
err = BCL_convertStringToBSTR(errLONG, -1)
MsgBox ("Error = " + err)
End If

and I would need the code to be written in a textbox on the report named
"streckoden"

Jen
 
You would probably put it in the Format event of the section that contains
the control, but it depends on what you are trying to do. If you are just
wanting a calculated textbox, you could use the equation as the Control
Source of the textbox.

To use in code and assign to the textbox:

Me.streckoden = CDbl(Me.text_amount.Value)
or
Me.streckoden = dblAmount

In the Control Source of the textbox:
=CDbl(Me.txt_amount.Value)

You can make these more complicated in the Control Source. You can also
write your own functions and use them in the Control Source.

I don't fully follow what you are trying to do in Excel. However, part of it
appears to be conditional formatting, you may want to look this up in the
Help file, it has some fairly good information on how to use the built-in
conditional formatting.
 
Back
Top