G
gr
Hi,
I have a Query qryTimeRecording which criteria is set in
two fields to:
[Forms]![frmChooseArea].[Form]![txtboxName]
[Forms]![frmChooseArea].[Form]![txtboxDate]
In a command button of frmChooseArea I want to open a
recordset based on the qryTimeRecording.
In order to know if there's an existing ID for that name
and date or not.
But my code is not working.
Here's my code:
Function CreateRecordset(strNombre As String, dtFecha As
Date) As Boolean
On Error GoTo CreateRecordsetErr
Dim rstData As ADODB.Recordset
Set rstData = New ADODB.Recordset
rstData.ActiveConnection = CurrentProject.Connection
rstData.CursorType = adOpenStatic
rstData.Open Source:="qryTimeRecording"
Do Until rstData.EOF
Debug.Print rstData![Names] & rstData![Dt]
rstData.MoveNext
Loop
If rstData.RecordCount = 0 Then
CreateRecordset = False
ElseIf rstData.RecordCount <> 0 Then
CreateRecordset = True
End If
MsgBox CreateRecordset
Salir_Fun:
rstData.Close
Set rstData = Nothing
Exit Function
CreateRecordsetErr:
MsgBox "Error " & Err.Number & ": " &
Err.Description
Resume Salir_Fun
End Function
The error message is: Invalid SQL statement.
The SQL of the query is:
SELECT tblName.NameID, tblName.Names, tblName.Dt,
tblTimeRecording.TimeRecID, tblTimeRecording.ActivityDesc,
tblTimeRecording.ProjectName, tblTimeRecording.SalesGrp,
tblTimeRecording.Hours, tblTimeRecording.ExtraTasks,
tblTimeRecording.MOO, tblTimeRecording.NCC,
tblTimeRecording.OfferX
FROM tblName INNER JOIN tblTimeRecording ON tblName.NameID
= tblTimeRecording.NameID
WHERE (((tblName.Names)=[Forms]![frmChooseArea].[Form]!
[txtboxName]) AND ((tblName.Dt)=[Forms]![frmChooseArea].
[Form]![txtboxDate]));
thx.
I have a Query qryTimeRecording which criteria is set in
two fields to:
[Forms]![frmChooseArea].[Form]![txtboxName]
[Forms]![frmChooseArea].[Form]![txtboxDate]
In a command button of frmChooseArea I want to open a
recordset based on the qryTimeRecording.
In order to know if there's an existing ID for that name
and date or not.
But my code is not working.
Here's my code:
Function CreateRecordset(strNombre As String, dtFecha As
Date) As Boolean
On Error GoTo CreateRecordsetErr
Dim rstData As ADODB.Recordset
Set rstData = New ADODB.Recordset
rstData.ActiveConnection = CurrentProject.Connection
rstData.CursorType = adOpenStatic
rstData.Open Source:="qryTimeRecording"
Do Until rstData.EOF
Debug.Print rstData![Names] & rstData![Dt]
rstData.MoveNext
Loop
If rstData.RecordCount = 0 Then
CreateRecordset = False
ElseIf rstData.RecordCount <> 0 Then
CreateRecordset = True
End If
MsgBox CreateRecordset
Salir_Fun:
rstData.Close
Set rstData = Nothing
Exit Function
CreateRecordsetErr:
MsgBox "Error " & Err.Number & ": " &
Err.Description
Resume Salir_Fun
End Function
The error message is: Invalid SQL statement.
The SQL of the query is:
SELECT tblName.NameID, tblName.Names, tblName.Dt,
tblTimeRecording.TimeRecID, tblTimeRecording.ActivityDesc,
tblTimeRecording.ProjectName, tblTimeRecording.SalesGrp,
tblTimeRecording.Hours, tblTimeRecording.ExtraTasks,
tblTimeRecording.MOO, tblTimeRecording.NCC,
tblTimeRecording.OfferX
FROM tblName INNER JOIN tblTimeRecording ON tblName.NameID
= tblTimeRecording.NameID
WHERE (((tblName.Names)=[Forms]![frmChooseArea].[Form]!
[txtboxName]) AND ((tblName.Dt)=[Forms]![frmChooseArea].
[Form]![txtboxDate]));
thx.