Syntax problem

×

×לי

Hi all!

I am using the following code in order to import records from access table.
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Documents
and Settings\Eli\My Documents\ETV_Cells.mdb"
rst.Open "SELECT DISTINCT [Printing_Date] FROM " & strTableName & "
ORDER BY [Printing_Date] ;", cnn, adOpenStatic
rst.MoveFirst

With Me.cboViewPrntDate
.Clear
Do
.AddItem rst![Printing_Date]
rst.MoveNext
Loop Until rst.EOF
End With

My problem is with changing the field name ([Printing_Date]) into a string
in order to use this code for more then one field instead of duplicating the
code for each field. I tried:
strField = "Printing_Date"
strField = "[Printing_Date]"
but i got error messages that was pointed to ".AddItem rst![Printing_Date]"
line.

Thanks in advance

Eli
 
B

Bob Phillips

rst.Open "SELECT DISTINCT [Printing_Date] FROM " & strTableName & "
ORDER BY [" & printDateVariable *& "] ;", cnn, adOpenStatic

HTH

Bob
 
M

Mike Fogleman

Use the Ampersand (&) for strField just like you did for strTableName.

Mike F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top