Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2004
    Posts
    57

    Unanswered: drawing a blank....

    I need a vacation...i'm having trouble remembering simple things....

    I need to write fields from an unbound form to a table using ado??? help???

  2. #2
    Join Date
    Feb 2004
    Posts
    533
    Quote Originally Posted by Geremia
    I need to write fields from an unbound form to a table using ado??? help???
    Just run an update query string in your Recordset open statement. Hint for an example of the ADO code just open a Switchboard form and view the VBA.

    Code:
    Private Sub ApplyAircraftNum()
      Dim con As Object
      Dim RS As Object
      Dim stSql As String
      Dim strFrmTxtValue
      
    Set con = Application.CurrentProject.Connection
        
      strFrmTxtValue = Me.txtField
      
      stSql = "Update tbL SET tbL.Field1 = " & _
              strFrmTxtValue & ", tbL.Field2 = 0 " & _
            " WHERE (((tbL.Index)=" & (Me.txtIndex) & "));"
            
            
        Set RS = CreateObject("ADODB.Recordset")
        
        ' Run the Update query to update teh table
        RS.Open stSql, con, 2   ' 1 = adOpenKeyset
        
    ' Close the recordset and the database.
        Set RS = Nothing
        Set con = Nothing
    
    End Sub
    ~

    Bill

  3. #3
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    Writing using ADO

    Another way of writing it as an example is:

    Function writeNewCustomer(PKCustomerID As Variant)
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    '** Write customer to dbo_WECCCustomers table
    Set rs = New ADODB.Recordset
    strSQL = "Select * from dbo_WECCCustomers where PKCustomerID = """ & PKCustomerID & """"
    rs.Open strSQL, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
    If Not rs.EOF And Not rs.BOF Then GoTo DupFound
    rs.AddNew
    rs!PKCustomerID = PKCustomerID
    rs!Prefix = Forms!MainForm!Prefix
    rs!FirstName = Forms!MainForm!FirstName
    ...etc
    rs.update
    rs.close
    set rs = nothing
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •