Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Forms / August 2004

Tip: Looking for answers? Try searching our database.

Loading Data into a droplist

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Blue - 12 Jul 2004 23:49 GMT
Hello,

I am trying to load data from an Access Database into a droplist...I found
the following code and changed the variable and the database location (which
doesn't seem to work or matbe I'm missing something):

Option Explicit
Dim txtCyberOther
Dim mobjchkOther
Dim chkOther
Dim cboCyber
Dim cboCyberProblem
Dim adoCyber

Function Item_Open()
Dim objInsp
Dim strCyber
Dim objPage

On Error Resume Next
strCyber = "C:\cyber.mdb"
Set adoCyber = OpenAccessDB(strCyber, "admin", "")

If Not adoCyber.State Is Nothing Then
Set objPage = _
Item.GetInspector.ModifiedFormPages("Message")
Set cboCyber = objPage.Controls("cboCyber")
Set cboCyberProblem = objPage.Controls("cboCyberProblem")
Call FillCyberList()
Call FillCyberProblemList()
End If

Set objInsp = Item.GetInspector
' set controls collection(s) and unbound text boxes
Set mobjchkOther = objInsp.ModifiedFormPages("Message").Controls
Set txtCyberOther = mobjchkOther("txtCyberOther")
Set chkOther = mobjchkOther("chkOther")
Set objInsp = Nothing

End Function

Function Item_Close()
On Error Resume Next
If adoCyber.State = adStateOpen Then
adoCyber.Close
End If
Set adoCyber = Nothing
Set cboCyber = Nothing
Set cboCyberProblem = Nothing
End Function

Sub FillCyberList()
Dim rstCybers
Dim strSQL
On Error Resume Next
Set rstCybers = CreateObject("ADODB.Recordset")
strSQL = "SELECT [Name]" & _
"from CyberAgents " & _
"ORDER BY [Name];"
rstCybers.Open strSQL, adoCyber, _
adOpenForwardOnly, adLockReadOnly
If rstCyber.State = adStateOpen Then
cboCyber.Column = rstCybers.GetRows
rstCybers.Close
End If
Set rstCybers = Nothing

End Sub

Sub FillCyberProblemList()
Dim rstCybersProblem
Dim strSQL
On Error Resume Next
Set rstCybersProblem = CreateObject("ADODB.Recordset")
strSQL = "SELECT [CyberProblems]" & _
"from Cyber Problems " & _
"ORDER BY [CyberProblems];"
rstCybersProblem.Open strSQL, adoCyber, _
adOpenForwardOnly, adLockReadOnly
If rstCybersProblem.State = adStateOpen Then
cboCyberProblem.Column = rstCybersProblem.GetRows
rstCybersProblem.Close
End If
Set rstCybersProblem = Nothing

End Sub

Function OpenAccessDB(strDBPath, UID, PWD)
Dim objADOConn
Dim strConn
On Error Resume Next
strConn = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=" & strDBPath & "; " & _
"User ID=" & UID & "; " & _
"Password=" & PWD & "; "
Set objADOConn = CreateObject("ADODB.Connection")
objADOConn.Open strConn
If (Err = 0) And (objADOConn.State = adStateOpen) Then
Set OpenAccessDB = objADOConn
Else
Set OpenAccessDB = Nothing
End If
Set objADOConn = Nothing

End Function

Sub chkOther_Click()
If mobjchkOther("chkOther").Value = True Then
mobjchkOther("txtCyberOther").Visible = True
End If
If mobjchkOther("chkOther").Value = False Then
mobjchkOther("txtCyberOther").Visible = False
End If

End Sub

Any help on this would be appreiaated...Thank you in advanced.

BLUE
Tom Rizzo [MSFT] - 13 Jul 2004 04:17 GMT
Maybe I missed it but where do you fill the drop-down with the values in the
code below?

Tom

Signature

Looking for a good book on programming Exchange, Outlook, ADSI and
SharePoint?  Check out http://www.microsoft.com/MSPress/books/5517.asp

This posting is provided "AS IS" with no warranties, and confers no rights.

> Hello,
>
[quoted text clipped - 115 lines]
>
> BLUE
BLUE - 13 Jul 2004 06:04 GMT
Tom,

It appears that I am missing that piece of code...Do you have an example of
how I would load the data into the dropdown list?

Signature

Billy Roberson Jr.
UOP
Web Technology

> Maybe I missed it but where do you fill the drop-down with the values in the
> code below?
[quoted text clipped - 121 lines]
> >
> > BLUE
Sue Mosher [MVP-Outlook] - 04 Aug 2004 14:10 GMT
No you're not. FillCyberList is what does it. Did you publish the form? Code
doesn't run on unpublished forms. You might want to add an
rstCybers.GetFirst statement before the GetRows statement.
Signature

Sue Mosher, Outlook MVP
Author of
    Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

> It appears that I am missing that piece of code...Do you have an example of
> how I would load the data into the dropdown list?
[quoted text clipped - 120 lines]
> > >
> > > BLUE
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.