Results 1 to 7 of 7
  1. #1
    skotseno is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    6

    Write Variable to Table (Newbie needs some help)

    I am brand new to this forum and pretty new to access. I have everything working except I can't figure out how to get access VBA to write values to my table.

    Table name: tblECN
    Variable in table that I would like to write a value for: Customer

    I have been scavenging the interweb in hopes of finding help with no avail so far. Here is my code:

    Private Sub chkCustomerAff_Click()
    Dim CustName As String


    'Dim strSQL As String
    'Dim db As DAO.Database
    'Set db = CurrentDb
    'Dim rstblECN As DAO.Recordset
    Dim rstblECN As Object
    'Set rstblECN = CurrentDb.OpenRecordset("Select * From Demographics Where False")
    CustName = InputBox("Customer name: ", "Customer Name", "Customer")
    If CustName <> "" And CustName <> "Customer" Then
    lblCustomer.Caption = CustName
    'strSQL="UPDATE tblECN SET Customer= '"&CustName&"' WHERE Customer=CustName"
    With rstblECN
    .Fields.Item("Customer") = CustName
    End With
    End If
    End Sub

    Sorry there are a lot of quoted out lines (I struggled with it for a while before giving up). Any help would be greatly appreciated.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,522
    Use a query.
    either append qry, or update qry.

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,535
    If you must use a recordset you will need to use AddNew or Edit and complete with Update. See the following link point 6 Adding a Record:
    http://www.utteraccess.com/wiki/inde...dding_a_Record
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by skotseno
    I am brand new to this forum and pretty new to access

    I cannot think of a worse way to learn about Access than using Unbound Forms! Using Unbound Forms does away with the main reason that developers choose to use Access, which is to take advantage of it ability to facilitate the RAD (Rapid Application Development) of Databases.

    With Bound Forms, Access does the vast majority of the heavy lifting; with Unbound Forms the developer has to write code for just about everything, even the most mundane tasks. Several developers I know, experienced in Visual Basic database development, as well as Access development, estimate that development, using Unbound Forms, by highly experienced developers, takes two to three times as long, using Unbound Forms, as it does when using Access and Bound Forms.

    In short, there is very little that can be done using Unbound Forms that cannot be accomplished with Bound Forms, and usually done with less work!

    Anyone who insists on using Unbound Forms, would be far better off using a straight VB or C++ front end with a SQL Server or Oracle back end.

    • You can create an EXE file which gives total protection to your code/design
    • You can distribute the db to PCs without a copy of Access being on board
    • Your data security is far, far better than anything you can do in Access


    It should be added that there are a few very specialized reasons for using Unbound Forms in Access, for general data entry of Records, but they are very specialized, and situations that a newbie is very unlikely to come upon. I've been writing Access apps for well over a decade now, and have never had the need for using Unbound Forms for general data entry.

    I applaud you efforts to learn Access, but you should first learn to use it as it is intended to be used, then you can move on to modifying its behavior, if the occasion arises.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    skotseno is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    6
    Quote Originally Posted by Bob Fitz View Post
    If you must use a recordset you will need to use AddNew or Edit and complete with Update. See the following link point 6 Adding a Record:
    http://www.utteraccess.com/wiki/inde...dding_a_Record
    Thanks! I used this link as well as some frustration but got it! Big help

  6. #6
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    Using unbound forms and binding data to them is a something you may find documented in legacy applications. Lots of vb6 apps were made this way even though binding through the controls properties was available. Its not bad or good.

  7. #7
    skotseno is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    6
    Quote Originally Posted by Perceptus View Post
    Using unbound forms and binding data to them is a something you may find documented in legacy applications. Lots of vb6 apps were made this way even though binding through the controls properties was available. Its not bad or good.
    I'm not sure why I keep getting messages about using unbound forms because that's not what I was doing. I was using a check box that triggered a input box to change the caption for the check box label. If the caption was changed, then I recorded the new caption in a table.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 05-18-2012, 07:31 AM
  2. Replies: 3
    Last Post: 12-21-2011, 10:49 AM
  3. Newbie. How do I use DLookup with a variable please?
    By graffiti in forum Programming
    Replies: 2
    Last Post: 12-12-2011, 08:59 AM
  4. VBA: Read table & write values to another table
    By compooper in forum Programming
    Replies: 6
    Last Post: 07-29-2011, 11:19 AM
  5. ODBC table read to blank Access table write
    By dibblejon in forum Access
    Replies: 2
    Last Post: 03-10-2010, 08:39 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums