Sending Data from Unbound field in form to table

  • I am trying to send data from a form to a table. You click on a push button and then it sends the data to the table.

    Right now I am testing. I am trying to test if I can send data from one field on the form to a field in the table but its not working. What do you recommend me to do ?

    I am getting this error (Run-time error 3058). Index or primary key cannot contain a Null value.

    How do I increment the primery key automatically?

    Private Sub Command45_Click()

    Dim db As DAO.Database

    Dim rst As DAO.Recordset

    Dim varTextData As String

    varTextData = Combo6

    Set db = CurrentDb

    Set rst = db.OpenRecordset("Waste Hauler Number", dbOpenDynaset)

    rst.AddNew

    rst!Classification = varTextData

    rst.Update

    rst.Close

    db.Close

    Me!Combo6 = ""

    End Sub

  • How do I increment the primery key automatically?

    I know how do this. I need to change Primery Key in the table to autonumber.

  • This is the solution.

    Private Sub Command45_Click()

    Dim db As DAO.Database

    Dim rst As DAO.Recordset

    Dim varTextData As String

    Dim varTextData2 As String

    Dim varTextData3 As String

    Dim varTextData4 As String

    Dim varTextData5 As String

    Dim varTextData6 As String

    Dim varTextData7 As String

    varTextData = Text31

    varTextData2 = Combo0

    varTextData3 = Combo2

    varTextData4 = Text27

    varTextData5 = Combo4

    varTextData6 = Combo6

    varTextData7 = Text25

    Set db = CurrentDb

    Set rst = db.OpenRecordset("Waste Hauler Number", dbOpenDynaset)

    rst.AddNew

    rst!WasteHaulerNumber = varTextData

    rst!HaulerID = varTextData2

    rst!Asset = varTextData3

    rst!AssetNumber = varTextData4

    rst!Material = varTextData5

    rst!Classification = varTextData6

    rst!DateYear = varTextData7

    rst.Update

    rst.Close

    db.Close

    Me!Combo0 = ""

    Me!Combo2 = ""

    Me!Text27 = ""

    Me!Combo4 = ""

    Me!Combo6 = ""

    End Sub

  • Some general information about forms in Access may be helpful as you continue your development. There are times where it is necessary or useful to use an unbound form and to force the user to click a button to save a record. However most Access forms are bound to a data source, which can be either a table or query, and in those cases you don't need any code to save a record - moving away from the record currently being added or edited automatically saves the data on the form for you. That is very useful in cases where you are using sub-forms in Access. That is also generally unique to Access - the beauty of it is that it reduces the amount of code you are required to write, and in general makes applications less complex, and thus less bug-prone.

    Wendell

    Wendell
    Colorful Colorado
    You can't see the view if you don't climb the mountain!

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply