+Malavika1990+
Please pull your image out of the DOCX file and post it directly.
+
- strSQL = strSQL [icode]+[icode] " Where
1) Change the plus to an ampersand " & "
2) insert
Following the strSQL line
3) When the code stops and the debugger opens, press <ctrl><G> to open the immediate pane.
4) Copy the SQL text
5) Go back to the main Access window
Ribbon>Create>Queries>QueryDesign
Cancel the show table dialog
Click on the [SQL] Bottom right hand corner (
see image here ) to switch to the SQL view
6) Paste the text you copied earlier
7) Run the query
This should return your result, if not, then you have a malformed string and you can post it here for us to take a look at...
+Your if then statement: YUCK
Better ways of doing this
Allen Browne: VBA Traps: Working with Recordsets
This is air code so there may be a typo or two
This is my preferred method for checking for records.
- If Rs1.RecordCount then
-
(if there is at least one record the recordcount will have 1 record regardless of the actual number of records )
-
end if
What is this?
Set tripConfirmObjectFormation.SchPickUp = New SchPickUp
Are you instancing a new form?
What is:
tripConfirmObjectFormation
What is:
SchPickUp
This is a harsh way to reference the field in the recordset
rs1.Fields(0).Value
+ Normally you would:
RS![FieldName]
to reference a value in the open recordset at the current record
+
[Forms]![CustomerTravelScheduleForm].EmployeeTravelTrnsId
If you are calling your code from "[CustomerTravelScheduleForm]" then this shortens to:
Me.EmployeeTravelTrnsId
if you are referring to the CONTROL value on the form if you are referring to the form's record set then
Me![EmployeeTravelTrnsId]
KEEP IN MIND
the default names for controls on the form are "ugly" as they default to the same name as the field to which they are bound. I cannot stress enough that people rename the control - even it it's something simple such as prefixing txt for a text box:
txtEmployeeTravelTrnsId
+ Testing for
Null or ZeroLength String (Read here)
I tend to use:
- If Not((rs1![FieldName] & "")="") Then
-
'your code here
-
Else
-
'Your Code here
-
End If
Ok, so until we verify that your SQL is actually returning records this should be a good start