Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access 2000 VBA module

Status
Not open for further replies.

David693

Programmer
Jan 23, 2003
4
CA
I feel silly asking this question. However, here goes.
I'm working in MS Access 2000, trying to write a Visual Basic module to open a table, and edit selected fields. VBA is new to me (old dBase & C++ guy!-that's me), and I can't seem to get started. So, what code do I use for the Declaration, and also for one function to, say, list one field. I'll be most grateful for help on this.
Thanks,
David693.
 
Code:
Sub UpdateRecord()
  Dim db As DAO.Database
  Dim rst As DAO.Recordset
  Dim strSQL As String
  
  strSQL = "SELECT * FROM [myTable] WHERE [myField] = 'Hello'"
  
  Set db = CurrentDb()
  Set rst = db.OpenRecordset(strSQL)
  
  With rst
    If .RecordCount > 0 Then
      .Edit
      .Fields("StringField") = "StringValue"
      .Fields("DateField") = #1/1/2002#
      .Update
      .Close
    End If
  End With
  
  On Error Resume Next
  Set rst = Nothing
  Set db = Nothing
End Sub
VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
Thank you, VBSlammer. Your code worked fine. (It turns out that I did not have the DAO 3.6 Library option checked off in Tools/References - that's why my code was not working. Ha!).
Regards, David 693.
PS-unemployed in Smithers, BC.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top