How can i access dynamic a database field. ( Is there something wrong with the Sub below ? )

'The DB is a public Variable that represent a database.

Public Sub WriteALineInList(Where, What)

Set frmtmp.Data1.Recordset = DB.OpenRecordset("Select * from AllFiles", dbOpenDynaset)

With frmtmp.Data1.Recordset
    ![Where] = What       'This is where i get the problem.
End With

End Sub

Thank you.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dirk HaestProject managerCommented:
Can you give this a try

.fields!where = what

Do this:

    .Fields(Where) = What    

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
...also, you might wanna declare the first argument as a string:

Public Sub WriteALineInList(Byval Where As String, What)
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Wich is the error code you get?
What is the data type of Where and what is the data type of What?  Might be a type mismatch.  If you want to convert a number to a string, then do something like:

.Fields(Where) = CStr(What)     ' convert to string

If you want to do the opposite, then:

.Fields(Where) = CLng(What)     '  convert to long


.Fields(Where) = CDbl(What)     ' convert to double

Have a look at Type Conversion Functions in your VB help.

Also, you want to specify the data types in your paramater declarations:

Public Sub WriteALineInList(Where as String, What as String)


Public Sub WriteALineInList(Where as Long, What as Double)

Whatever is appropriate...


mrenosAuthor Commented:
Thank jarnsater. This one line saved me. :-)
Even that it worked also with the : .Fields(Where).Value = Where
I tryed last night before i see your message.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.