Problem with referring variable's value

  • Thread starter Thread starter Sunny
  • Start date Start date
S

Sunny

I need help in VAB code. This is extraction of my code:

VariableField1 = 50
VariableField2 = 100

lblfld1 = "VariableField1"
lblfld1 = "VariableField2"


Now is there anyway to get VariableField1 value (which is 50) by referring
lblfld1 ?
 
No way that I can think of, no. Why would you want to? (I ask, not only out
of curiosity, but because if we knew that we might be able to suggest an
alternative solution).

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
I need this for one of my general report. Before displaying report, I create
temprory table and store values. Each time table has different field names.
I want to use these field names as column title and value of the field in
detail section.
 
Try:

VariableField1 = 50
VariableField2 = 100

lblfld1 = Eval(VariableField1)
lblfld2 = Eval(VariableField2)
 
Hi
I've used this in the report open event
Me.Controls.Item("<name of your field>").Caption = "<the literal stuff
you want>" & Forms!<name of form to get info from>!<name of control to get
info from>

replace the <> with your fields.
Marc
 
I need this for one of my general report. Before displaying report, I
create
temprory table and store values. Each time table has different field
names.
I want to use these field names as column title and value of the field in
detail section.

referring to control, or field in a recordset (table) can most certainly be
done at runtime.

so, to work with, or set the value of a control on a form, you can go:

strField = inputbox("Display what value from the he from?")

msgbox me(strField)

Or, if the form is out side of the current form, then go:

forms!YourFormName(strField).

The above also works with reports, and also works with recorded data. So,
for your use (a report), then you should be just fine.


rstRecordSetDate(strYourFieldName).
 
Maybe you can adapt this to your needs. This is DAO code. If you don't
already have it, you'll need to add a reference (Tools, References in the
VBA editor) to the Microsoft DAO 3.6 Object Library. Alternatively, if you
are more familiar with ADO, it should not be difficult to adapt this code to
use ADO instead. This code assumes that the recordset will not contain more
fields than there are controls on the report. It could be made more robust
by adding a check for that.

Private Sub Report_Open(Cancel As Integer)

Dim lngLoop As Long
Dim rst As DAO.Recordset
Dim db As DAO.Database

Set db = CurrentDb
Set rst = db.OpenRecordset(Me.RecordSource)
For lngLoop = 0 To rst.Fields.Count - 1
Me.Controls("Label" & lngLoop + 1).Caption =
rst.Fields(lngLoop).Name
Me.Controls("Textbox" & lngLoop + 1).ControlSource =
rst.Fields(lngLoop).Name
Next lngLoop

End Sub

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Back
Top