Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Format INTO MS Access

Status
Not open for further replies.

SkiCheif

Technical User
Sep 8, 2004
30
US
I almost have it working!

I am having a date problem trying to submit a form into an MS Access database.

After searching around the Tek-Tips forum i suspect it has to do with the 'pound sign' format that Access expects.

The error message is that there is a syntax error on my INSERT INTO string.

To counteract it, I was trying to populate the hidden text field via a cookie and concantenate in '#' on each side.

Here is the code:
-------------------------------
<input name="txtMatchDate" type="hidden" id="txtMatchDate" value="#" & <%= Request.Cookies("MatchSetup")("MatchDate") %> & "#">
-------------------------------

The cookie data looks like this:
MatchDate=9%2D15%2D2004&VisitingTeam=Del+Val&HomeTeam=Del+Val

The date in a textbox that is not hidden looks like this: 9-15-2004

I am using a DateTimePicker to select the date so that the format is consistant and can change the hypen.

I remember that sending a "/" or some other symbols are forbidden, is that the problem??

Either I am concantanating incorrectly or I am wrong about the formatting problem.

Thanks for your help..
 
can you show us the INSERT statement too please.

It may well be because of the # that you have in the textbox around the date. You might have to wait until the SQL statement before using that.

Also - try doing a Response.Write of your SQL statement followed by a Response.End to show you the exact SQL that is being passed.

Tony
________________________________________________________________________________
 
for access to be happy, and to make life easier on you it's best for access and your system to run on the LCID info for dates, the easiest way to do this is Cdate() a datevalue before inserting it into the db

second note, #'s ARE necessary for Access to be happy with dates .. but concactenating the #'s on the value is not wise, especially if it's cookied, cause then the cookie will continually grow ( next visit to page adds ANOTHER pair of #'s to the cookie value ) ... only put the #'s on in the actual SQL statements, it'll save some headaches.

"where dateval = #" & cdate(mydateval) & "#"

[thumbsup2]DreX
aKa - Robert
 
Here is the insert statement. I am slightly ashamed to say that I am using DreamweaverMX to write the code. Not typically my way of doing things, but this is so new, I don't have time to do it from scratch (with my experience level).

The part that I have bolded, is where I changed the code when I wrote my MSAccess version. Basically I added a test for a date and changed the single quotes to a pound sign. Sorry to say that I haven't a clue on how to go about that here.

----------------------------------

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "75_weigh_class_frm") Then

MM_editConnection = MM_TestConnection_STRING
MM_editTable = "tbl_Match_Results"
MM_editRedirectUrl = ""
MM_fieldsStr = "txtWeightClass|value|cboHomeWrestler|value|cboVisitingWrestler|value|cboHomeWrestlerScore|value|cboVisitingWrestlerScore|value|txtHomeSeed|value|txtVisitingSeed|value|txtHomeMatch|value|txtVisitingMatch|value|txtHomeTeam|value|txtVisitingTeam|value|txtMatchDate|value"
MM_columnsStr = "Weight_Class|',none,''|Home_Wrestler_Name|',none,''|Visitng_Wrestler_Name|',none,''|Home_Wrestler_Score|',none,''|Visiting_Wrestler_Score|',none,''|Home_Wrestler_Seed_Pts|none,none,NULL|Visiting_Wrestler_Seed_Pts|none,none,NULL|Home_Team_Points|none,none,NULL|Visiting_Team_Pts|none,none,NULL|Home_Team|',none,''|Visiting_Team|',none,''|Date|',none,NULL"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If

----------------------------------

I am no very good a arrays, so I typically do it the long way. Is there a way to test for a date field and change just that one?

Thanks, this probably one of the harder things I have tried to do.
 
Is there a way to test for a date field and change just that one?
You could use the IsDate() function to determine if the value represented a valid date. If it returns a TRUE then insert the # signs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top