473,474 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

To display data using query in a form.

16 New Member
hai all,
Please help me, i was trying to rerive data using query and that data has to display in the form. But the problem is data is, data which is retrived by the query is not coming to the form. please help me.
Expand|Select|Wrap|Line Numbers
  1. strSQL = strSQL + " Where (CustomerTravelTrns.EmployeeTravelTrnsId = ScheduledTripTrns.EmployeeTravelTrnsId and EmployeeMstr.R3EmployeeMstrId = ScheduledTripTrns.R3EmployeeMstrId and ScheduledTripTrns.FlightStatus='Arrival' and (CustomerTravelTrns.EmployeeTravelTrnsId)=" & [Forms]![CustomerTravelScheduleForm].EmployeeTravelTrnsId & ");"
  2.  Set rs1 = db.OpenRecordset(strSQL)
This is the Query.
Expand|Select|Wrap|Line Numbers
  1. If (Not IsNull(rs1) And Not (rs1.EOF)) Then
  2.   Set tripConfirmObjectFormation.SchPickUp = New SchPickUp
  3.   If (Not IsNull(rs1.Fields(0).Value)) Then
  4.    tripConfirmObjectFormation.SchPickUp.SchArrvPickDate = rs1.Fields(0).Value
  5.   End If
Attached Files
File Type: docx screen shot.docx (18.2 KB, 263 views)
Aug 10 '18 #1
14 3473
zmbd
5,501 Recognized Expert Moderator Expert
+Malavika1990+
Please pull your image out of the DOCX file and post it directly.

+
Expand|Select|Wrap|Line Numbers
  1. strSQL = strSQL [icode]+[icode] " Where 
1) Change the plus to an ampersand " & "
2) insert
Expand|Select|Wrap|Line Numbers
  1. debug.print strSQL
  2. Stop
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.
Expand|Select|Wrap|Line Numbers
  1. If Rs1.RecordCount then
  2. (if there is at least one record the recordcount will have 1 record regardless of the actual number of records )
  3. 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:
Expand|Select|Wrap|Line Numbers
  1. If Not((rs1![FieldName] & "")="") Then
  2.  'your code here
  3. Else
  4.  'Your Code here
  5. End If
Ok, so until we verify that your SQL is actually returning records this should be a good start
Aug 10 '18 #2
NeoPa
32,556 Recognized Expert Moderator MVP
If the data is not showing on the form you need to follow these steps :
  1. Determine the exact SQL of the RecordSource (We also may need to see this if you still have problems after following these steps carefully).
  2. Determine if, using the SQL determined in step #1 above, you see the data you're expecting to see on the form but don't.
  3. Determine which Control on the form is the one you would have expected to see the data on.
If you're still having problems then lets see the results of your steps above and we'll see if we can help.
Aug 11 '18 #3
Malavika1990
16 New Member
@ZMbd
Thank you for the reply, while trying to run the query in the above mentioned process, it is asking for parameter values. why it is asking like that? did i have done any mistake?
Aug 13 '18 #4
zmbd
5,501 Recognized Expert Moderator Expert
Malavika1990:
If the query is asking you for information then the SQL is most likely malformed.

Post your SQL from the query you tried to run, please use the [CODE/] formatting in the tool bar on your SQL string.
Aug 13 '18 #5
Malavika1990
16 New Member
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT ScheduledTripTrns.PickupDate
  2. , ScheduledTripTrns.PickupTime
  3. , ScheduledTripTrns.[Pickup Location]
  4. , ScheduledTripTrns.[Dropoff Location]
  5. , ScheduledTripTrns.TotalTripAmount
  6. , EmployeeMstr.R3EmployeeName
  7. , EmployeeMstr.CellPhone
This is the query.
Aug 13 '18 #6
NeoPa
32,556 Recognized Expert Moderator MVP
Malavika1990:
This is the query.
Seriously? What you've posted isn't workable SQL. It has no FROM clause to match the two different sources you're obviously trying to use.

PS. It's basic manners to respond to all posts where someone is offering their help.
Aug 13 '18 #7
zmbd
5,501 Recognized Expert Moderator Expert
Malavika1990,
I'm guessing you didn't post the entire resolved SQL string as in post #1 you have a WHERE clause that clearly isn't in the SQL snipit in your last post.

Please follow my instructions as given in Post#2

Also, PLEASE extract your image from the docx file in post#1 and upload it directly. Many of us cannot, or will not, download and open files due to business rules or simple "PC-Hygiene" - if you will extract the image and upload it direct within your post we can push the thumbnail to the message.

You need to help us to help you!
Aug 13 '18 #8
Malavika1990
16 New Member
Zmbd
The code is is not breaking to debug mode. it is working fine, but the details are not coming into the outlook mail.Only name of the cutomer is coming remaing detalis are not coming.
i dont know how to extract the image from this question.
Aug 14 '18 #9
Malavika1990
16 New Member
Sorry i have posted only half of the sql query.
Aug 14 '18 #10
NeoPa
32,556 Recognized Expert Moderator MVP
Malavika1990:
Sorry i have posted only half of the sql query.
I would suggest the obvious next step is to correct that by posting the full SQL then, as soon as possible.
Aug 14 '18 #11
Malavika1990
16 New Member
Thanks for your response, sql is now working fine.But the data is not displaying in the mail.
Aug 14 '18 #12
Malavika1990
16 New Member
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT ScheduledTripTrns.PickupDate
  2.   , ScheduledTripTrns.PickupTime
  3.   , ScheduledTripTrns.[Pickup Location]
  4.   , ScheduledTripTrns.[Dropoff Location]
  5.   , ScheduledTripTrns.TotalTripAmount
  6.   , EmployeeMstr.R3EmployeeName
  7.   , EmployeeMstr.CellPhone 
  8. FROM cellPhoneMstr
  9.   , EmployeeMstr, CustomerTravelTrns
  10.   , ScheduledTripTrns
  11. WHERE (
  12.   CustomerTravelTrns.EmployeeTravelTrnsId =
  13.     ScheduledTripTrns.EmployeeTravelTrnsId 
  14.   AND 
  15.     EmployeeMstr.R3EmployeeMstrId =
  16.       ScheduledTripTrns.R3EmployeeMstrId 
  17.   AND 
  18.     (CustomerTravelTrns.EmployeeTravelTrnsId)= " &
  19.       [Forms]!CustomerTravelScheduleForm].EmployeeTravelTrnsId & ")
This is the actual query
Aug 14 '18 #13
zmbd
5,501 Recognized Expert Moderator Expert
Malavika1990:
Where did this query come from?
It certainly doesn't look like what I was expecting as a resolved string from the VBA code.
For one thing I was expecting that [Forms]!CustomerTravelScheduleForm].EmployeeTravelTrnsId
would have been replaced by the value in the [EmployeeTravelTrnsId] field - if this is a string value then you already have a format issue with the quotes.

Please advise, did you follow my instructions to obtain the resolved string the code is using or did you pull this out of some other source?
Aug 14 '18 #14
Malavika1990
16 New Member
Thanks to all for your support now the application is working fine.
Aug 15 '18 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sasha | last post by:
Hi All, I am new to VB.Net and am having a problem with the below code. I am trying to fill in a datagrid with the below query but it keeps giving me error where the *'s are located below. I...
4
by: zwasdl | last post by:
Is it possible to view access query (design view or sql view) and its query results in the same window (for example, arrange them side by side) as other DB software do? Thanks, Wei
2
by: weird0 | last post by:
Below is the code I wrote but it aint working.... : It throws an exception on DataBind() statement that "the source does not support server-side paging". PLz Help. Really stuck. protected...
2
by: jej1216 | last post by:
Using PHP to populate a form, I am not able to display any text area data -- it displays as blank. <?php echo "<textarea rows=11 cols=120 name=inc_descr value='".$incdescr."'></textarea>"; ?> ...
2
by: freddy windey | last post by:
Hi, this my 1st time i join discussion. im just a new programmer. i need help from your expert on this "Insert data using 1 form to 2 different table"- ASP VBscript. example- name: age: DOB:...
1
by: glaw333 | last post by:
Ok this might sound a bit stupid but I'm relatively new to this. I'll explain the background - I'm setting up a database of accounts that people have with my company. I've set up all the tables and...
17
by: lee weaver | last post by:
I have a form to edit employee data that is a copy of the add employee form ( Which works great) with a list box at the top to select the employee to edit that is susposed to navigate to the correct...
1
by: rhonda2010 | last post by:
I have a program in which I want to have the user enter two percentages and display the data matching the criteria on a new form. The query would be: Select * From Corrosion Where corrpct1 >=...
7
by: huda89 | last post by:
Hi, I would like to ask, is it possible if i would like to display data in one form from two different table in database? Thank you. =)
1
by: skg0009 | last post by:
Hi, I need to create a Form for big Excel, where I can update data using the form instead of excel. Like we do in MS Access is there anything available like Form wizard. As it's a big excel...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.