save timestamp upon click of save button (1 Viewer)

ili_sophia

Registered User.
Local time
Today, 07:00
Joined
Aug 23, 2017
Messages
40
hi there,

i have a date time stamp on a form but i realise that it will save the date and time when the form is opened.

i would like for the actual date and time to be saved when the save command button is clicked.

i have tried to add the code Me.DateTimeStamp = Now() but it gives the error of you can't assign a value to this object

code for save button:
Private Sub cmdSave_Click()
'Insert data to MaximMaintable by using SQL
CurrentDb.Execute "Insert into MaximMainTable (GLGPO,Mill,[Solid/Printing],Reference,FunctionalFinish,MRName,Buyer,MXDPO,GLA,StyleNo,FabricDelivery,GarmentDelDate,Country,Fabrication,AfterFabricWashWidth,Width,FinishedGoods,GSMPerSqYd,GSMAfterWash,Colour,GroundColour,ComboName,LabDipCode,SampleRequirement,GrossWeight,NettWeight,Lbs,Loss,Yds,Remarks,GarmentSketch,[GarmentSketch2],[GarmentSketch3],[GarmentSketch4],[GarmentSketch5],PrintedRemarks,FabricWeight,UnitPrice,Line,PPSample,POStatus,Amendment,SketchRemark1,SketchRemark2,SketchRemark3,SketchRemark4,SketchRemark5,DateTimeStamp)" & _
"Values (" & Me.txtGLGPO & ",'" & Me.cboMill & "','" & Me.cboSP & "','" & Me.cboReference & "','" & Me.cboFunctionalFinish & "','" & Me.txtMRName & "','" & Me.txtBuyer & "','" & Me.txtMXDPO & "','" & Me.txtGLA & "','" & Me.txtStyleNo & "','" & Me.txtFabricDelivery & "','" & Me.txtGarmentDelDate & "','" & Me.txtCountry & "','" & Me.txtFabrication & "','" & Me.txtFabricWashWidth & "','" & Me.txtWidth & "','" & Me.txtFinishedGoods & "','" & _
Me.txtGSMsq & "','" & Me.txtGSMAfterWash & "','" & Me.txtColour & "','" & Me.txtGroundColour & "','" & Me.txtComboName & "','" & Me.txtLabDipsCode & "','" & Me.txtBuyerRequirement & "','" & Me.txtGrossweight & "','" & _
Me.txtNettweight & "','" & Me.txtLbs & "','" & Me.txtLoss & "','" & _
Me.txtYds & "','" & Me.txtRemarks & "','" & Me.txtGarmentSketch & "','" & Me.txtGarmentSketch2 & "','" & Me.txtGarmentSketch3 & "','" & Me.txtGarmentSketch4 & "','" & Me.txtGarmentSketch5 & "','" & Me.txtPrintedRemarks & "','" & Me.txtFabricWeight & "','" & Me.TXTuNITpRICE & "','" & Me.txtLine & "','" & Me.txtPPSample & "','" & Me.txtPOStatus & "','" & Me.txtAmendment & "','" & Me.txtSketchRemark1 & "','" & Me.txtSketchRemark2 & "','" & Me.txtSketchRemark3 & "','" & Me.txtSketchRemark4 & "','" & Me.txtSketchRemark5 & "','" & Me.DateTimeStamp & "')"

Me.DateTimeStamp = Now()

'Click on save, all the fields in the textbox will be clear
cmdClear_Click
'Refresh data in list on form to show only data that are not save
UnmatchFabricPOqrysubform.Form.Requery

End Sub
 

Mark_

Longboard on the internet
Local time
Yesterday, 16:00
Joined
Sep 12, 2017
Messages
2,111
Several things,
First, can you please use the code tab (#) when posting code? It helps make it much more readable.

Second, you are trying to set the value AFTER you are executing the insert.

Third, as you are using CurrentDb.Execute to do your insert, I would highly recommend either putting your SQL string together in a string variable PRIOR to executing (so you can view exactly what is being executed) OR look at doing a parameter based insert.

Fourth why are you using CurrendDb.Execute instead of using a bound form? With a bound form you could default your value and let ACCESS take care of doing the insert.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 18:00
Joined
Feb 28, 2001
Messages
27,226
ili_sophia - I second Mark_'s comments about bound forms.

One of the really GREAT abilities of Access is that if you can just set up the forms correctly, you can let it do a LOT of your work for you. As much as I sometimes feel that Access is dumber than a box of rocks, it makes a GREAT scaffold for some really neat and often impressive applications. Just learn to let it work for you and suddenly things will get easier. (Never truly easy - but easiER.)
 

Users who are viewing this thread

Top Bottom