Link to home
Start Free TrialLog in
Avatar of mrenos
mrenos

asked on

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
   
    .AddNew
    ![Where] = What       'This is where i get the problem.
    .Update
    .Close
   
End With

End Sub


Thank you.
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Can you give this a try

.addnew
.fields!where = what

ASKER CERTIFIED SOLUTION
Avatar of jarnsater
jarnsater

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jarnsater
jarnsater

...also, you might wanna declare the first argument as a string:

Public Sub WriteALineInList(Byval Where As String, What)
...
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

-or-

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

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

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

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

-or-

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

Whatever is appropriate...

Preece

Avatar of mrenos

ASKER

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.