passing variable in field name

  • Thread starter Thread starter Ken Snell [MVP]
  • Start date Start date
K

Ken Snell [MVP]

Drop the quotes around the variable name.

Data1.Recordset.Fields(strparts).Value = txtpart.Text

Also, you don't want to use .Text (the control must have the focus to use
..Text). Use .Value instead.
 
i am trying to find out if it is possiable to use a variable instead of a
field name
when using access 97. i have 2 text boxes and these will change per the
users input.
the databas is set up with many diff fields. here is an example of theway i
am trying to do it now.. please help


Dim strseek As String
Dim parts As String
strparts = txtopt.Text
strseek = txtpart.Text

' i am trying to use strparts as a variable
Data1.Recordset.FindFirst "strparts=" & "'" & strseek & "'"

If Data1.Recordset.NoMatch = True Then
Data1.Recordset.AddNew

Data1.Recordset.Fields("date").Value = txtdate.Text
Data1.Recordset.Fields("location").Value = txtbox.Text

Data1.Recordset.Fields("strparts").Value = txtpart.Text( i want this field
to be able to change per the users input)


Data1.Recordset.Fields("qty").Value = txtqty.Text
Else
Data1.Recordset.Fields("qty").Value = txtqty.Text +
Data1.Recordset.Fields("qty").Value

End If
 
Just to tag along on Ken's (absolutely correct) advice.

If you really do have a field named Date in your table, I'd suggest renaming
it. Date is a reserved word, and using reserved words can lead to problems.

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)
 
Back
Top