behöver en funkton som säger "ja boka" om dagens datum inte finns i access databasen Varför ingår inte datumet som vilkor i din SQL fråga? Bokar man en eller flera dagar samtidigt? Hej Anders En enkel lösning är att använda Filter. Du måste nog då öppna recordsetet med statisc cursor istället för att köra Execute vilket retunerar en Forward Only cursor. Hej och tack!problem med NOT sats
"If objRecordset.Fields("Day") = iCurrent Then" fungerar för att hitta de dagar som finns i databasen med aktivitet. MEN hur får jag ett villkor typ "else" där jag kan skriva "ja boka" för de dagar som inte finns i accessdatabasen?
'PROBLEMET JAG INTE LÖSER
'denna funktion skall svar ja om qua_idate är 1 el 2 men Fullt om 3 - OK
'problem hur bokar man dagar som inte finns i accessdatabas?
'en funktion som säger boka? om aktuell "day" inte finns i databasen
If Not objRecordset.BOF Then
objRecordset.MoveFirst
Do Until objRecordset.EOF
If objRecordset.Fields("Day") = iCurrent Then
typeOfEvent = objRecordset.Fields("qua_idate")
select case typeOfEvent
case 1
Response.Write("1 boka")
case 2
Response.Write("2 boka")
case 3
Response.Write("3 fullt")
case else
end select
End If
objRecordset.MoveNext
Loop
End If
'response.write("<br>")
'response.write("boka1?")
end ifSv: problem med NOT sats
Om datumet ingår i villkoret kan du direkt avgöra om det finns någon post eller inte genom att kontrollera EOF egenskapen för ditt recordset.
Om du postar mer av din kåd så kan vi ger dig fler/bättre förslag.Sv:problem med NOT sats
Minns att du hjälpte mig med en access databas för några år sedan, har inte glömt det, än en gång tack för hjälpen!
Det här problemet är lite för svårt för mig, maila om du vill ha access databasen. Tacksam för din hjälp!
<%@ LANGUAGE=VBSCRIPT %>
<%Option Explicit%>
<!--include file="adovbs.inc"-->
<%
If Request.Form("AddEvent") = "Add Event" Then
Response.Redirect("add_event.asp")
End If
If Request.Form("EditEvent") = "Edit Event" Then
Response.Redirect("edit_event.asp")
End If
'*** CHANGES HERE
Dim DB_CONNECTIONSTRING
Dim objRecordset
Dim objConnection
Dim sSQL
'*** Take away the ADO-stuff from here
'Set objRecordset = Server.CreateObject("ADODB.Recordset")
'objRecordset.Open "calendar", DB_CONNECTIONSTRING, adOpenStatic, adLockPessimistic, adCmdTable
%>
<%
Function GetDaysInMonth(iMonth, iYear)
Select Case iMonth
Case 1, 3, 5, 7, 8, 10, 12
GetDaysInMonth = 31
Case 4, 6, 9, 11
GetDaysInMonth = 30
Case 2
If IsDate("February 29, " & iYear) Then
GetDaysInMonth = 29
Else
GetDaysInMonth = 28
End If
End Select
End Function
Function GetWeekdayMonthStartsOn(iMonth, iYear)
GetWeekdayMonthStartsOn = WeekDay(iYear & "-" & iMonth & "-01", vbMonday)
End Function
Function SubtractOneDay(dDate)
Dim iDay, iMonth, iYear
iDay = Day(dDate)
iMonth = Month(dDate)
iYear = Year(dDate)
If iDay = 1 Then
iDay = 30
iYear = iYear - 1
Else
iDay = iDay - 1
End If
If iDay > GetDaysInMonth(iMonth, iYear) Then iDay = GetDaysInMonth(iMonth, iYear)
SubtractOneDay = CDate(iMonth & "-" & iDay & "-" & iYear)
End Function
Function SubtractOneMonth(dDate)
Dim iDay, iMonth, iYear
iDay = Day(dDate)
iMonth = Month(dDate)
iYear = Year(dDate)
If iMonth = 1 Then
iMonth = 12
iYear = iYear - 1
Else
iMonth = iMonth - 1
End If
If iDay > GetDaysInMonth(iMonth, iYear) Then iDay = GetDaysInMonth(iMonth, iYear)
SubtractOneMonth = CDate(iMonth & "-" & iDay & "-" & iYear)
End Function
Function AddOneMonth(dDate)
Dim iDay, iMonth, iYear
iDay = Day(dDate)
iMonth = Month(dDate)
iYear = Year(dDate)
If iMonth = 12 Then
iMonth = 1
iYear = iYear + 1
Else
iMonth = iMonth + 1
End If
If iDay > GetDaysInMonth(iMonth, iYear) Then iDay = GetDaysInMonth(iMonth, iYear)
AddOneMonth = CDate(iMonth & "-" & iDay & "-" & iYear)
End Function
Dim dDate ' Date we're displaying calendar for
Dim iDIM ' Days In Month
Dim iDOW ' Day Of Week that month starts on
Dim iCurrent ' Variable we use to hold current day of month as we write table
Dim iPosition ' Variable we use to hold current position in table
Dim tempDate ' Used to hold a temporary date when constructing the
' variables below.
Dim previousDay ' gårdagens datum
Dim today ' omskrivning av dagens datum
Dim previousMonth ' Variables (strings) holding the dates for the
Dim nextMonth ' previous, next month respectivley.
' To be used for fetching the next/previous month in the
' calendar.
Dim typeOfEvent ' Is it a race or for everybody etc.
If IsDate(Request.QueryString("date")) Then
dDate = CDate(Request.QueryString("date"))
Else
tempDate = Request("year") & "-" & Request("month(dDate)") & "-" & Request("day")
If IsDate(tempDate) Then
dDate = tempDate
Else
dDate = Date()
If Request.QueryString.Count <> 0 Then
Response.Write "The date you picked was not a valid date. The calendar was set to today's date.<BR><BR>"
End If
End If
End If
iDIM = GetDaysInMonth(Month(dDate), Year(dDate))
iDOW = GetWeekdayMonthStartsOn(Month(dDate), Year(dDate))
tempDate = SubtractOneDay(dDate)
'previousDay = Year(tempDate) & "-" & month(Date) & "-" & day(tempDate)
previousDay = month(Date) & "/" & day(tempDate) & "/" & Year(tempDate)
response.write(previousday)
tempDate = SubtractOneMonth(dDate)
previousMonth = Year(tempDate) & "-" & month(tempDate) & "-" & day(tempDate)
tempDate = AddOneMonth(dDate)
nextMonth = Year(tempDate) & "-" & month(tempDate) & "-" & day(tempDate)
today = Year(Date) & "-" & month(Date) & "-" & day(Date)
%>
<html>
<SCRIPT Language=JavaScript>
function OpenEventWin(ID)
{
window.open('display_event2.asp?ID=' + ID,'Event','width=690,height=500,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=Yes,copyhistory=no');
}
</SCRIPT>
<head>
</head>
<BODY>
<link href="include/style.css" rel="stylesheet" type="text/css">
<table border="1" align="center" cellpadding="1" cellspacing="0">
<tr bgcolor="000000">
<td colspan="7" align="center">
<table width="600" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<%
' A form with two controls for year and month are built.
%>
<td align="LEFT" VALIGN="BOTTOM" bordercolor="#000000">
<FORM NAME="FAST_SELECT" ACTION="calendar.asp" METHOD="GET">
<INPUT TYPE="HIDDEN" NAME="date" VALUE="x">
<INPUT TYPE="HIDDEN" NAME="day" VALUE="1">
<B><font face="Arial">
<BR> <SELECT NAME="year" onChange="javascript:document.FAST_SELECT.submit();">
<%
Dim i
For i = 1999 to 2010
Response.Write("<OPTION ")
if (i = year(dDate)) then
Response.Write("SELECTED ")
end if
Response.Write("VALUE=""" & i & """>" & i & vbNewLine)
next
%>
</SELECT>
<SELECT NAME="month" onChange="javascript:document.FAST_SELECT.submit();">
<%
For i = 1 to 12
Response.Write("<OPTION ")
if (i = month(dDate)) then
Response.Write("SELECTED ")
end if
Response.Write("VALUE=""" & i & """>" & MonthName(i) & vbNewLine)
next
%>
</SELECT>
</FONT>
</B>
</FORM>
</TD>
<td align="right"><b><--</b></td>
<td align="center"><font color="#FFFFFF"><b><font face="Arial"><%= MonthName(Month(dDate)) & " " & Year(dDate) %></font></b></font></td>
<td align="left"><b>--></b></td>
</tr>
</table> </td>
</tr>
<tr bgcolor="000000">
<td width="80" align="center"><b><font color="#FFFFFF" face="Arial">Mån</font></b></td>
<td width="80" align="center"><b><font color="#FFFFFF" face="Arial">Tis</font></b></td>
<td width="80" align="center"><b><font color="#FFFFFF" face="Arial">Ons</font></b></td>
<td width="80" align="center"><b><font color="#FFFFFF" face="Arial">Tor</font></b></td>
<td width="80" align="center"><b><font color="#FFFFFF" face="Arial">Fre</font></b></td>
<td width="80" align="center"><b><font color="#FFFFFF" face="Arial">Lör</font></b></td>
<td width="80" align="center"><b><font color="#FFFFFF" face="Arial">Sön</font></b></td>
</tr>
<%
If iDOW <> 1 Then
Response.Write(vbTab & "<tr>" & vbCrLf)
iPosition = 1
Do While iPosition < iDOW
Response.Write(vbTab & vbTab & "<td> </td>" & vbCrLf)
iPosition = iPosition + 1
Loop
End If
'-- Write days of month in proper day slots --
iCurrent = 1
iPosition = iDOW
'response.Write(WeekdayName(weekday(ddate)))
'*** CHANGES HERE:
' For numerical values in year and month
sSQL = "SELECT qua_idate, DAY FROM qry_calendar WHERE year = " & year(dDate) & _
" AND month = " & month(dDate)
'DB_CONNECTIONSTRING = "DSN=d1994-nbas;Password=@01#$pggfhoaeoidblabknbhkihlg" & ";"
DB_CONNECTIONSTRING = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("/") & "\include\main_db.mdb;"
'strDb = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("/") & "\include\nbas.mdb;"
Set objConnection = Server.CreateObject("ADODB.Connection")
Set objRecordset = Server.CreateObject("ADODB.Recordset")
objConnection.Open DB_CONNECTIONSTRING
set objRecordset = objConnection.Execute(sSQL)
Do While iCurrent <= iDIM
'-- open the table row --
If iPosition = 1 Then
Response.Write(vbTab & "<tr>" & vbCrLf)
End If
'-- Write the date and subject --
Response.Write(vbTab & vbTab & "<td align=left valign=top height=50><b>" & iCurrent & "</b>")
Dim redday 'alla dagar före idag är röda
redday = (DateDiff("d",month(dDate) & "/" & icurrent & "/" & year(dDate),Date))
if redday > -10 Then 'spärrar bokning 10 dagar fram i tiden
Response.write("<br>")
response.Write ("<img src=images/a.gif>")
else
if iPosition = 6 Then 'rödmarkerar lördag
Response.write("<br>")
response.Write ("<img src=images/a.gif>")
elseif iPosition = 7 Then ' rödmarkerar söndagar
Response.write("<br>")
response.Write ("<img src=images/a.gif>")
elseif iPosition < 6 Then
'PROBLEMET JAG INTE LÖSER
'denna funktion skall svar ja om qua_idate är 1 el 2 men Fullt om 3 - OK
'problem hur bokar man dagar som inte finns i accessdatabas?
'en funktion som säger boka? om aktuell "day" inte finns i databasen
If Not objRecordset.BOF Then
objRecordset.MoveFirst
Do Until objRecordset.EOF
If objRecordset.Fields("Day") = iCurrent Then
typeOfEvent = objRecordset.Fields("qua_idate")
select case typeOfEvent
case 1
Response.Write("1 boka")
case 2
Response.Write("2 boka")
case 3
Response.Write("3 fullt")
case else
end select
'Response.Write("<br><font size=2>" & objRecordset.Fields("Subject") & "</font><br>")
'Response.write("<FONT SIZE=3>" & objRecordset.Fields("Subject") & "</font><br>")
End If
objRecordset.MoveNext
Loop
End If
'response.write("<br>")
'response.write("boka1?")
end if
end if
Response.Write("</td>" & vbCrLf)
'-- Close the table row --
If iPosition = 7 Then
Response.Write vbTab & "</tr>" & vbCrLf
iPosition = 0
End If
'-- Increment variables --
iCurrent = iCurrent + 1
iPosition = iPosition + 1
Loop
objRecordset.Close
objConnection.Close
set objConnection = nothing
set objRecordset = nothing
If iPosition <> 1 Then
Do While iPosition <= 7
Response.Write(vbTab & vbTab & "<td> </td>" & vbCrLf)
iPosition = iPosition + 1
Loop
Response.Write vbTab & "</TR>" & vbCrLf
End If
%>
</table>
</td>
</tr>
</table>
</center>
</body>
</html>Sv: problem med NOT sats
objRecordset.Filter = "Day = #" & iCurrent & "#"
If objRecordset.EOF Then
Response.Write("0 boka")
Else
typeOfEvent = objRecordset.Fields("qua_idate")
select case typeOfEvent
case 1
Response.Write("1 boka")
case 2
Response.Write("2 boka")
case 3
Response.Write("3 fullt")
case else
end select
'Response.Write("<br><font size=2>" & objRecordset.Fields("Subject") & "</font><br>")
'Response.write("<FONT SIZE=3>" & objRecordset.Fields("Subject") & "</font><br>")
end if
Men något åt detta hållet borde väl fungera?
Sv:problem med NOT sats
Funktionen fungerar utmärkt med execute
'set objRecordset = objConnection.Execute(sSQL)
set objRecordset = objConnection.adOpenStatic(sSQL)
Vad gör jag fel denna gång?Sv: problem med NOT sats
set objRecordset = CreateObject("ADODB.Recordset")
objRecordset.Open sSQL, objConnection, adOpenStatic