Hi
I posted a question recently regarding problems I am having getting a
value from a list box to use in a query. I got a lot of help, for
which I thank you and it's nearly working! But I need a little more
help on one more point.
This is what i've got. I have code that hunts for updated
appointments in a public folder based on the order that happens to be
open (code fires on an on open event) This works fine and updates my
appointments table with no problem if I run the code manually and
select each appointment item manually in my list box on the order
form.
My problem is, if I run the code from an on open event, it doesn't
loop through the values in my list box, it just returns 0 as a value
as follows:
UPDATE tblSMSchedule SET tblSMSchedule.strNotes = 'Wrthwrthtes mmm'
WHERE tblSMSchedule.cntID = 0
The rest of my code looks like this:
Option Compare Database
Public Function ImportAppointmentsTest()
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("tblSMSchedule")
Dim Prop As Outlook.UserProperty
Dim objOL As New Outlook.Application
Dim objNS As Outlook.NameSpace
Dim strFind As String
Dim objCalFolder As Outlook.mapiFolder
Dim AllPublicFolders As Outlook.mapiFolder
Dim MyPublicFolder As Outlook.mapiFolder
Dim colCalendar As Outlook.Items
Dim objAppt As Outlook.AppointmentItem
Dim db As Database
Dim rsAppointmentsRecords As Recordset
Dim str As String
Dim TableName As String
Set db = CurrentDb
Dim myOlApp
Dim mNameSpace
Dim MyItem
Dim strMsg
Dim strPublicFolder
Dim strSubject
Dim strStart
Dim strEnd
Dim strBody
Dim strLocation
Dim strRequiredAttendees
Dim strCategories
Dim strBillingInformation
Dim strShow
Dim strUniqueID
Dim val As Integer, i As Integer
Dim ctl As Control
Const olAppointmentItem = 1
strPublicFolder = ("Office")
If Len(strPublicFolder) > 0 Then
Set objOL = CreateObject("Outlook.Application")
Set mNameSpace = objOL.GetNamespace("MAPI")
Set objCalFolder = mNameSpace.Folders("Public Folders")
Set AllPublicFolders = objCalFolder.Folders("All Public Folders")
Set MyPublicFolder = AllPublicFolders.Folders("Office")
Set colCalendar = MyPublicFolder.Items
strFind = "[Billinginformation] = " &
Forms!frmOEOrder!txtOrderNumber & ""
strShow = "" & Forms!frmOEOrder!txtOrderNumber & ""
Set objAppt = colCalendar.Find(strFind)
If objAppt Is Nothing Then
strSQL = "DELETE tblSMSchedule.strOrderNumber FROM
tblSMSchedule WHERE tblSMSchedule.strOrderNumber = '" & strShow & "'"
DoCmd.RunSQL strSQL
Else
Set rst = CurrentDb.OpenRecordset("tblSMSchedule")
rst.MoveLast
rst.MoveFirst
Do Until rst.EOF
If rst(19) = strShow Then
With objAppt
strLocation = .Location
strSubject = .Subject
strStart = .Start
strBody = .Body
End With
Set ctl = Forms!frmOEOrder!ListSchedule
For i = 0 To ctl.ListCount - 1
If ctl.Selected(i) Then
val = ctl.Column(0, i)
Exit For
End If
Next i
str = "UPDATE tblSMSchedule SET tblSMSchedule.strNotes = '" & strBody
& "' WHERE tblSMSchedule.cntID = " & val
DoCmd.RunSQL (str)
End If
rst.MoveNext
Loop
rst.Close
db.Close
Set objOL = Nothing
Set objNS = Nothing
Set objCalFolder = Nothing
Set colCalendar = Nothing
End If
End If
End Function
Any Ideas' ? 7 2488
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Use the Form_Load event instead of Form_Open event to read data from a
ListBox.
When the form opens there aren't any items SELECTED from the ListBox, so
what are you getting from the ListBox? Couldn't you just use a
Recordset with the ListBox's RowSource as the query?
An UPDATE doesn't return anything (except error messages, if any), so
what are you expecting?
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBQT9lBoechKqOuFEgEQKdngCfb4Ehh1ZLze7Jcw2B5M4gnn BRO2IAoOsb
65i+rdMoNEwkPZe7FpYDlicK
=mbed
-----END PGP SIGNATURE-----
Dave Hopper wrote: Hi
I posted a question recently regarding problems I am having getting a value from a list box to use in a query. I got a lot of help, for which I thank you and it's nearly working! But I need a little more help on one more point.
This is what i've got. I have code that hunts for updated appointments in a public folder based on the order that happens to be open (code fires on an on open event) This works fine and updates my appointments table with no problem if I run the code manually and select each appointment item manually in my list box on the order form.
My problem is, if I run the code from an on open event, it doesn't loop through the values in my list box, it just returns 0 as a value as follows:
UPDATE tblSMSchedule SET tblSMSchedule.strNotes = 'Wrthwrthtes mmm' WHERE tblSMSchedule.cntID = 0
< SNIP >
MGFoster <me@privacy.com> wrote in message news:<ey****************@newsread3.news.pas.earthl ink.net>... -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Use the Form_Load event instead of Form_Open event to read data from a ListBox.
When the form opens there aren't any items SELECTED from the ListBox, so what are you getting from the ListBox? Couldn't you just use a Recordset with the ListBox's RowSource as the query?
An UPDATE doesn't return anything (except error messages, if any), so what are you expecting?
-- MGFoster:::mgf00 <at> earthlink <decimal-point> net Oakland, CA (USA)
-----BEGIN PGP SIGNATURE----- Version: PGP for Personal Privacy 5.0 Charset: noconv
iQA/AwUBQT9lBoechKqOuFEgEQKdngCfb4Ehh1ZLze7Jcw2B5M4gnn BRO2IAoOsb 65i+rdMoNEwkPZe7FpYDlicK =mbed -----END PGP SIGNATURE-----
Dave Hopper wrote:
Hi
I posted a question recently regarding problems I am having getting a value from a list box to use in a query. I got a lot of help, for which I thank you and it's nearly working! But I need a little more help on one more point.
This is what i've got. I have code that hunts for updated appointments in a public folder based on the order that happens to be open (code fires on an on open event) This works fine and updates my appointments table with no problem if I run the code manually and select each appointment item manually in my list box on the order form.
My problem is, if I run the code from an on open event, it doesn't loop through the values in my list box, it just returns 0 as a value as follows:
UPDATE tblSMSchedule SET tblSMSchedule.strNotes = 'Wrthwrthtes mmm' WHERE tblSMSchedule.cntID = 0 < SNIP >
Hi, Thanks for the response
The code doesn't work under a button on the form either. However if
you select an item and click the button it functions perfectly for
that entry.
My list box contains appointments that are assigned to the order on
the form. There could be up to ten appointments for an order, so when
the form opens, or when you move to the next record, I need the code
to run and pull in data from the public folder calendar to update the
backend appointments table and refresh the form to show the new data.
As I said, the code seems to find the correct appointments but it
can't find the list box source to complete the update query unless you
highlight an entry.
Any ideas' ?
Dave Hopper
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
You could use the Form's OnCurrent event instead of OnOpen or OnLoad
events. The OnCurrent event fires every time a record is accessed. In
that event you could run the code that does whatever you want.
Since the code only works when an item in the ListBox is selected, this
means that the code is probably using the ListBox's ItemsSelected
property. If you want to use ALL the items in a ListBox you would have
to loop thru the items, both selected & unselected. Do you want all the
items?
Here's one way to get all items in a ListBox:
' Get the items in a specific column (1) of the indicated ListBox:
Dim lst As ListBox
Set lst = Me!lstAppts ' Set ref to the ListBox
Dim row As Integer
For row = 0 To lst.ListCount - 1
Debug.Print lst.Column(1, row) ' Get the column we want
Next row
You can modify to your needs.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBQUDvboechKqOuFEgEQJ5gwCg/08jYcegBJmtHl/9ce+dVTrdVf4AoKLf
15Fjq6bbj256ZIxqXWwV1gLP
=4N78
-----END PGP SIGNATURE-----
Dave Hopper wrote: MGFoster <me@privacy.com> wrote in message news:<ey****************@newsread3.news.pas.earthl ink.net>...
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Use the Form_Load event instead of Form_Open event to read data from a ListBox.
When the form opens there aren't any items SELECTED from the ListBox, so what are you getting from the ListBox? Couldn't you just use a Recordset with the ListBox's RowSource as the query?
An UPDATE doesn't return anything (except error messages, if any), so what are you expecting?
-- MGFoster:::mgf00 <at> earthlink <decimal-point> net Oakland, CA (USA)
-----BEGIN PGP SIGNATURE----- Version: PGP for Personal Privacy 5.0 Charset: noconv
iQA/AwUBQT9lBoechKqOuFEgEQKdngCfb4Ehh1ZLze7Jcw2B5M4gnn BRO2IAoOsb 65i+rdMoNEwkPZe7FpYDlicK =mbed -----END PGP SIGNATURE-----
Dave Hopper wrote:
Hi
I posted a question recently regarding problems I am having getting a value from a list box to use in a query. I got a lot of help, for which I thank you and it's nearly working! But I need a little more help on one more point.
This is what i've got. I have code that hunts for updated appointments in a public folder based on the order that happens to be open (code fires on an on open event) This works fine and updates my appointments table with no problem if I run the code manually and select each appointment item manually in my list box on the order form.
My problem is, if I run the code from an on open event, it doesn't loop through the values in my list box, it just returns 0 as a value as follows:
UPDATE tblSMSchedule SET tblSMSchedule.strNotes = 'Wrthwrthtes mmm' WHERE tblSMSchedule.cntID = 0
< SNIP >
Hi, Thanks for the response
The code doesn't work under a button on the form either. However if you select an item and click the button it functions perfectly for that entry.
My list box contains appointments that are assigned to the order on the form. There could be up to ten appointments for an order, so when the form opens, or when you move to the next record, I need the code to run and pull in data from the public folder calendar to update the backend appointments table and refresh the form to show the new data.
As I said, the code seems to find the correct appointments but it can't find the list box source to complete the update query unless you highlight an entry.
Any ideas' ?
Dave Hopper
MGFoster <me@privacy.com> wrote in message news:<Mb*****************@newsread3.news.pas.earth link.net>... -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
You could use the Form's OnCurrent event instead of OnOpen or OnLoad events. The OnCurrent event fires every time a record is accessed. In that event you could run the code that does whatever you want.
Since the code only works when an item in the ListBox is selected, this means that the code is probably using the ListBox's ItemsSelected property. If you want to use ALL the items in a ListBox you would have to loop thru the items, both selected & unselected. Do you want all the items?
Here's one way to get all items in a ListBox:
' Get the items in a specific column (1) of the indicated ListBox: Dim lst As ListBox Set lst = Me!lstAppts ' Set ref to the ListBox Dim row As Integer For row = 0 To lst.ListCount - 1 Debug.Print lst.Column(1, row) ' Get the column we want Next row
You can modify to your needs. -- MGFoster:::mgf00 <at> earthlink <decimal-point> net Oakland, CA (USA)
-----BEGIN PGP SIGNATURE----- Version: PGP for Personal Privacy 5.0 Charset: noconv
iQA/AwUBQUDvboechKqOuFEgEQJ5gwCg/08jYcegBJmtHl/9ce+dVTrdVf4AoKLf 15Fjq6bbj256ZIxqXWwV1gLP =4N78 -----END PGP SIGNATURE-----
Dave Hopper wrote:
MGFoster <me@privacy.com> wrote in message news:<ey****************@newsread3.news.pas.earthl ink.net>...
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Use the Form_Load event instead of Form_Open event to read data from a ListBox.
When the form opens there aren't any items SELECTED from the ListBox, so what are you getting from the ListBox? Couldn't you just use a Recordset with the ListBox's RowSource as the query?
An UPDATE doesn't return anything (except error messages, if any), so what are you expecting?
-- MGFoster:::mgf00 <at> earthlink <decimal-point> net Oakland, CA (USA)
-----BEGIN PGP SIGNATURE----- Version: PGP for Personal Privacy 5.0 Charset: noconv
iQA/AwUBQT9lBoechKqOuFEgEQKdngCfb4Ehh1ZLze7Jcw2B5M4gnn BRO2IAoOsb 65i+rdMoNEwkPZe7FpYDlicK =mbed -----END PGP SIGNATURE-----
Dave Hopper wrote:
Hi
I posted a question recently regarding problems I am having getting a value from a list box to use in a query. I got a lot of help, for which I thank you and it's nearly working! But I need a little more help on one more point.
This is what i've got. I have code that hunts for updated appointments in a public folder based on the order that happens to be open (code fires on an on open event) This works fine and updates my appointments table with no problem if I run the code manually and select each appointment item manually in my list box on the order form.
My problem is, if I run the code from an on open event, it doesn't loop through the values in my list box, it just returns 0 as a value as follows:
UPDATE tblSMSchedule SET tblSMSchedule.strNotes = 'Wrthwrthtes mmm' WHERE tblSMSchedule.cntID = 0
< SNIP >
Hi, Thanks for the response
The code doesn't work under a button on the form either. However if you select an item and click the button it functions perfectly for that entry.
My list box contains appointments that are assigned to the order on the form. There could be up to ten appointments for an order, so when the form opens, or when you move to the next record, I need the code to run and pull in data from the public folder calendar to update the backend appointments table and refresh the form to show the new data.
As I said, the code seems to find the correct appointments but it can't find the list box source to complete the update query unless you highlight an entry.
Any ideas' ?
Dave Hopper
Hi
I have modified the code and can get it to work on it's own, but I
can't seem to get it to work with my sql pasted elsewhere in this
thread. When your code runs on it's own, it produces the desired
result and pulls out all the values correctly. I need to be able to
insert those values into my query by setting a variable. For example
i = lst.Column(1, row). I can then use the value i in my sql as
follows:
str = "UPDATE tblSMSchedule SET tblSMSchedule.strNotes = '" & strBody
& "' WHERE tblSMSchedule.cntID = " & i
DoCmd.RunSQL (str)
However, when I enter this, I get an error telling me that it is
expecting a sub ?
I'm sorry to be a pain, but could you show me exactly where I need to
insert this code to get the desired result. I'm normally pretty good
at modifying code for my own needs, but I'm just drawing a mental
blank with this
Many thanks in anticipation for your help.
Dave
Dave Hopper wrote: MGFoster <me@privacy.com> wrote in message news:<Mb*****************@newsread3.news.pas.earth link.net>...
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
You could use the Form's OnCurrent event instead of OnOpen or OnLoad events. The OnCurrent event fires every time a record is accessed. In that event you could run the code that does whatever you want.
Since the code only works when an item in the ListBox is selected, this means that the code is probably using the ListBox's ItemsSelected property. If you want to use ALL the items in a ListBox you would have to loop thru the items, both selected & unselected. Do you want all the items?
Here's one way to get all items in a ListBox:
' Get the items in a specific column (1) of the indicated ListBox: Dim lst As ListBox Set lst = Me!lstAppts ' Set ref to the ListBox Dim row As Integer For row = 0 To lst.ListCount - 1 Debug.Print lst.Column(1, row) ' Get the column we want Next row
You can modify to your needs. -- MGFoster:::mgf00 <at> earthlink <decimal-point> net Oakland, CA (USA)
-----BEGIN PGP SIGNATURE----- Version: PGP for Personal Privacy 5.0 Charset: noconv
iQA/AwUBQUDvboechKqOuFEgEQJ5gwCg/08jYcegBJmtHl/9ce+dVTrdVf4AoKLf 15Fjq6bbj256ZIxqXWwV1gLP =4N78 -----END PGP SIGNATURE-----
Dave Hopper wrote:
MGFoster <me@privacy.com> wrote in message news:<ey****************@newsread3.news.pas.earthl ink.net>...
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Use the Form_Load event instead of Form_Open event to read data from a ListBox.
When the form opens there aren't any items SELECTED from the ListBox, so what are you getting from the ListBox? Couldn't you just use a Recordset with the ListBox's RowSource as the query?
An UPDATE doesn't return anything (except error messages, if any), so what are you expecting?
-- MGFoster:::mgf00 <at> earthlink <decimal-point> net Oakland, CA (USA)
-----BEGIN PGP SIGNATURE----- Version: PGP for Personal Privacy 5.0 Charset: noconv
iQA/AwUBQT9lBoechKqOuFEgEQKdngCfb4Ehh1ZLze7Jcw2B5M4gnn BRO2IAoOsb 65i+rdMoNEwkPZe7FpYDlicK =mbed -----END PGP SIGNATURE-----
Dave Hopper wrote: >Hi > >I posted a question recently regarding problems I am having getting a >value from a list box to use in a query. I got a lot of help, for >which I thank you and it's nearly working! But I need a little more >help on one more point. > >This is what i've got. I have code that hunts for updated >appointments in a public folder based on the order that happens to be >open (code fires on an on open event) This works fine and updates my >appointments table with no problem if I run the code manually and >select each appointment item manually in my list box on the order >form. > >My problem is, if I run the code from an on open event, it doesn't >loop through the values in my list box, it just returns 0 as a value >as follows: > >UPDATE tblSMSchedule SET tblSMSchedule.strNotes = 'Wrthwrthtes mmm' >WHERE tblSMSchedule.cntID = 0 >
< SNIP >
Hi, Thanks for the response
The code doesn't work under a button on the form either. However if you select an item and click the button it functions perfectly for that entry.
My list box contains appointments that are assigned to the order on the form. There could be up to ten appointments for an order, so when the form opens, or when you move to the next record, I need the code to run and pull in data from the public folder calendar to update the backend appointments table and refresh the form to show the new data.
As I said, the code seems to find the correct appointments but it can't find the list box source to complete the update query unless you highlight an entry.
Any ideas' ?
Dave Hopper
Hi
I have modified the code and can get it to work on it's own, but I can't seem to get it to work with my sql pasted elsewhere in this thread. When your code runs on it's own, it produces the desired result and pulls out all the values correctly. I need to be able to insert those values into my query by setting a variable. For example i = lst.Column(1, row). I can then use the value i in my sql as follows:
str = "UPDATE tblSMSchedule SET tblSMSchedule.strNotes = '" & strBody & "' WHERE tblSMSchedule.cntID = " & i DoCmd.RunSQL (str)
However, when I enter this, I get an error telling me that it is expecting a sub ?
I'm sorry to be a pain, but could you show me exactly where I need to insert this code to get the desired result. I'm normally pretty good at modifying code for my own needs, but I'm just drawing a mental blank with this
Many thanks in anticipation for your help.
Dave
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I don't know what that error report is. A "sub"! What's a sub?
Is the SQL string correct. Is the cntID a string or a number? Make
sure it has the proper delimiters if it is a string.
I use "CurrentDB.Execute str, dbFailOnError" instead of RunSQL. The
Execute w/ dbFailOnError gives a more exact error report.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/AwUBQUIZLYechKqOuFEgEQKHdwCeJR8RrK8bNGpHjN4RCFFxHL J6dt0AnRN2
K+2xL1KTmvZJKEZQXKf3ahBX
=3Ce7
-----END PGP SIGNATURE-----
try this instead
DBEngine(0)(0).Execute strSQL, dbFailOnError
try this instead
DBEngine(0)(0).Execute strSQL, dbFailOnError This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bruce W...1 |
last post by:
I do a query to MySQL using PHP. Well actually I do too many of them
which is the problem, it's too slow. I think maybe an inner join or...
|
by: Muhd |
last post by:
To start off i have a database table that consists of "profiles", another
that consists of "users" and finally one that consists of "exclusions",...
|
by: KoliPoki |
last post by:
Greetings.
I'm having a little trouble with a query. The idea is simple I need to
display a list of recently unique visited URLs and the last...
|
by: |
last post by:
having a spot of trouble writing this one. if you are so inclined and have a
moment, i'd really appreciate your insight.
i have what amounts to a...
|
by: baustin75 |
last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie
only when debugging in php designer 2005
...
|
by: hope |
last post by:
Hi
Access 97
I'm lost on this code please can you help
=================================
Below is some simple code that will concatenate a...
|
by: Steve Patrick |
last post by:
Hi All
You guys are my last hope, despite spending money on books and hours reading
them I still can not achieve the results I need.
I have...
|
by: Zlatko Matić |
last post by:
Hello.
How to reference selected values from a multi-select list box, as a
criteria in a query ?
Is it possible at all?
Regards,
Zlatko
|
by: Frank11 |
last post by:
Hi, I'm rather new to writing queries, so please forgive me if this is a really simple thing to do.
I need to create a query that finds out which...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...
| |