Solved Save date from unbound text box to table (1 Viewer)

saledo2000

Registered User.
Local time
Today, 23:28
Joined
Jan 21, 2013
Messages
94

Attachments

  • error.png
    error.png
    4.1 KB · Views: 115
  • FD_Structure.png
    FD_Structure.png
    9.3 KB · Views: 111

Isaac

Lifelong Learner
Local time
Today, 16:28
Joined
Mar 14, 2017
Messages
8,738
Ok, then I think the problem might be with the date value from that unbound textbox.
I know there are many date formats out there, so it might just be that I am unfamiliar, but:
Code:
dd.mm.yyyy. hh:mm:ss
does not look like any acceptable date format that I've ever seen. Try entering the date in the unbound textbox as
Code:
6/27/2020 1:40 pm
and then run your code and see what happens.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 07:28
Joined
May 7, 2009
Messages
19,169
updated my sample.
it will load the records from tblFD.
 

Attachments

  • food.zip
    37.7 KB · Views: 118

saledo2000

Registered User.
Local time
Today, 23:28
Joined
Jan 21, 2013
Messages
94
Ok, then I think the problem might be with the date value from that unbound textbox.
I know there are many date formats out there, so it might just be that I am unfamiliar, but:
Code:
dd.mm.yyyy. hh:mm:ss
does not look like any acceptable date format that I've ever seen. Try entering the date in the unbound textbox as
Code:
6/27/2020 1:40 pm
and then run your code and see what happens.
My date has format Short date dd.mm.yyyy on the form in unbound box and in the tblFD field as well e.g. 26.06.2020.
 

Isaac

Lifelong Learner
Local time
Today, 16:28
Joined
Mar 14, 2017
Messages
8,738
Actually I just looked closer at your error that you posted the screenshot.

Looks like you forgot to add the second #
Copy the code that I had given you exactly.
 

saledo2000

Registered User.
Local time
Today, 23:28
Joined
Jan 21, 2013
Messages
94
Actually I just looked closer at your error that you posted the screenshot.

Looks like you forgot to add the second #
Copy the code that I had given you exactly.

There is a code with your suggestion.
Private Sub cmdAdd_Date_Click()
Dim strSQL As String
strSQL = "INSERT INTO Food_Distribution (FD_Date) VALUES(#" & Me.txtUnboundDate & "#)"
CurrentDb.Execute strSQL
DoCmd.RunCommand acCmdSaveRecord
End Sub

Error on screenshot does not show last #. I have checked and error is the same.
 

Isaac

Lifelong Learner
Local time
Today, 16:28
Joined
Mar 14, 2017
Messages
8,738
Looks good.
Did you look at the error message you posted? In the error message, it shows an insert value without the second # symbol.
The code you just posted looks good.
 

saledo2000

Registered User.
Local time
Today, 23:28
Joined
Jan 21, 2013
Messages
94
Looks good.
Did you look at the error message you posted? In the error message, it shows an insert value without the second # symbol.
The code you just posted looks good.
Yes I have checked three times and code has both # but error still occur. By the way thank you for helping me to solve this trivial problem but I am new in Access world. Learning every day hard and hope to get where you are guys.
 

Attachments

  • error.png
    error.png
    7.7 KB · Views: 118
Last edited:

Isaac

Lifelong Learner
Local time
Today, 16:28
Joined
Mar 14, 2017
Messages
8,738
Hmm, odd. You could try adding a space after the word value and see if that helps. There must be something else going on that I can't see.
 

Isaac

Lifelong Learner
Local time
Today, 16:28
Joined
Mar 14, 2017
Messages
8,738
Attached is a database where I have the exact same table, same table column, same textbox, same command button and click event code as you do (minus the DoCmd.RunCommand acCmdSaveRecord, since you have stated that your code errs before that line, and my form isn't bound).

The code works fine.

Thus, something else is going on that I can't see.
 

Attachments

  • Testing 20200626_2.accdb
    400 KB · Views: 111

saledo2000

Registered User.
Local time
Today, 23:28
Joined
Jan 21, 2013
Messages
94
updated my sample.
it will load the records from tblFD.
I have tried your solution and if I select the yesterday date or any other date even present date I get an error.
 

Attachments

  • error1.png
    error1.png
    26.3 KB · Views: 105

saledo2000

Registered User.
Local time
Today, 23:28
Joined
Jan 21, 2013
Messages
94
Attached is a database where I have the exact same table, same table column, same textbox, same command button and click event code as you do (minus the DoCmd.RunCommand acCmdSaveRecord, since you have stated that your code errs before that line, and my form isn't bound).

The code works fine.

Thus, something else is going on that I can't see.
Thanks I will try and post feedback
 

saledo2000

Registered User.
Local time
Today, 23:28
Joined
Jan 21, 2013
Messages
94
Attached is a database where I have the exact same table, same table column, same textbox, same command button and click event code as you do (minus the DoCmd.RunCommand acCmdSaveRecord, since you have stated that your code errs before that line, and my form isn't bound).

The code works fine.

Thus, something else is going on that I can't see.
There is a screenshot to get picture what I am trying to achieve.
 

Attachments

  • FD Form.png
    FD Form.png
    29 KB · Views: 105

Pat Hartman

Super Moderator
Staff member
Local time
Today, 19:28
Joined
Feb 19, 2002
Messages
42,979
I'm having trouble trying to figure out the purpose of running an append query to insert a single row into a table with a single column. Wouldn't you at least want to know what meal your're talking about and how many people were served for that meal? I think you need at least three columns and you would never run an append query to enter this data because you would be missing data for at least two fields.
tblFoodServed:
ServigsID (autonumber PK)
ServeDT (today's date)
MealType (breakfast, lunch, dinner, other)
PeopleServed (a count of how many people were served)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 07:28
Joined
May 7, 2009
Messages
19,169
i hope this fixed the issue of your Date Regional setting.
 

Attachments

  • food.zip
    51.5 KB · Views: 130

saledo2000

Registered User.
Local time
Today, 23:28
Joined
Jan 21, 2013
Messages
94
i hope this fixed the issue of your Date Regional setting.
Thank you very much arnelgp. I have included your solution in my DB and it works. You are the man. I wish to buy you a beer. I have another question if you can help. I have UNION query of multiple Entry and Exit date and I have made another query out of UNION query. But I cannot put criteria to insert a date to get results only for that date. I have added =[Enter date] into criteria but I do not get any record. There is a screenshot of my query and results without criteria
Thanks mate for your help
 

Attachments

  • Entry date.png
    Entry date.png
    14.5 KB · Views: 112

Users who are viewing this thread

Top Bottom