Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Sending Data from Unbound field in form to table Expand / Collapse
Author
Message
Posted Friday, November 30, 2012 10:54 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, January 11, 2013 11:52 AM
Points: 28, Visits: 50
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
Post #1391462
Posted Friday, November 30, 2012 11:14 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, January 11, 2013 11:52 AM
Points: 28, Visits: 50
How do I increment the primery key automatically?


I know how do this. I need to change Primery Key in the table to autonumber.
Post #1391474
Posted Friday, November 30, 2012 11:57 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, January 11, 2013 11:52 AM
Points: 28, Visits: 50
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
Post #1391487
Posted Saturday, December 1, 2012 6:37 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 4:27 PM
Points: 169, Visits: 624
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!
Post #1391683
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse