Problem with .AddNew syntax

K

keith

Hello,

I am using an example from the Access help system to create and write
records to a DAO database. Below is a piece of the code from the example.
This example writes two variables that have been defined in the table:
“firstname†and “lastnameâ€.

With tdf
.AddNew
!firstname = Str(count)
!lastname = "abc"
.Update
End With

In my table, however, the program creates the table, and then adds
variables. One time, the variables might be “firstname†and “lastnameâ€, and
another time they might be “Var1†and “Var2â€

I can store the variables as strings. For example, String1 might be
“firstname†one time, and “Var1†another time, but what syntax would be used
in the above code to identify the variable name? Using a statement like…

!String1 = MyData

Doesn’t work.

Any suggestions?

Thank you,

Keith
 
J

jpr

I hope I'm understanding your question right. Try this out. Create two
string variables strField1 and strField2. These will hold the names of the
fields in the table. The first example assumes the two fields are "LastName"
and "FirstName". The second example assumes the fields are "Var1" and "Var2".

The syntax is the key here. Look in example 1.
The line tdf(strField1) = Str(count)
translates to
tdf!FirstName = str(count)

Example 1:
Dim strField1 as string
Dim strField2 as string

strField1 = “FirstNameâ€
strField2 = “LastNameâ€
With tdf
.AddNew
tdf(strField1) = Str(count)
tdf(strField2) = "abc"
.Update
End With

Example 2:
Dim strField1 as string
Dim strField2 as string

strField1 = “Var1â€
strField2 = “Var2â€
With tdf
.AddNew
tdf(strField1) = Str(count)
tdf(strField2) = "abc"
.Update
End With
 
K

keith

Hello JPR.

Thanks very much. It looks like this will do the trick.
I'll give it a try.
Keith
 

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