LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Join string with variable name to get variable value

For the first time ever, I'm trying to get some Excel97 data into
Access97 with VBA.

I have a module with some module-level variables declared, e.g.
Dim mstrProjectName as String

In one of my procedures, I select some data from Access into a
recordset. What I want to do is to go through the fields in the
recordset, get the name of the field, the value from Access and the
value from my Excel variable and load them into a listbox on a form and
show it to the user. The Excel variables have the same name as the
Access fields, except that they're prefixed by mstr (or whatever).

I can't get the listbox's List property to accept "mstr" & fieldName as
a variable name -- it treats it as a string "mstrProjectName", and my
listbox has "mstrProjectName" as column 2 instead of the value the
variable holds.

Any advice is appreciated...

If rs.RecordCount < 0 Then 'If this record exists in the database
rs.MoveFirst

For Each fldLoop In rs.Fields

strFieldName = fldLoop.Name
vntFieldValue = fldLoop.Value
If IsNull(vntFieldValue) Then vntFieldValue = ""

With frmExistingProject.lstDifferences
.AddItem intCounter
.List(intCounter, 0) = strFieldName
.List(intCounter, 1) = vntFieldValue
If strFieldName = "ProjectValue" Then
'This is my only non-string variable and works OK
.List(intCounter, 2) = mcurProjectValue
Else
'This doesn't work
.List(intCounter, 2) = "mstr" & strFieldName
End If
End With

intCounter = intCounter + 1

Next fldLoop
End If

--
Thanks,
Dianne


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable string$ Ferdy New Users to Excel 3 November 26th 08 08:45 PM
Use a string as a Variable Name Brandt Excel Worksheet Functions 4 November 28th 07 06:01 PM
Variable in string DevinC Excel Discussion (Misc queries) 5 January 26th 06 08:59 PM
join location string with variable excel programming[_2_] Excel Programming 0 August 28th 03 03:46 AM
join location string with variable igor Excel Programming 4 August 27th 03 02:46 AM


All times are GMT +1. The time now is 01:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"