Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Code 2

Status
Not open for further replies.

assets

Technical User
Oct 23, 2002
574
AU
The code bleow is in a Word Document.
Option Explicit

Private Sub ComboBox2_Change()
ActiveDocument.FormFields("Text2").Result = ComboBox2.Value
End Sub

Private Sub CmdClose_Click()
End
End Sub



Private Sub UserForm_Initialize()
Dim dbDatabase As Database
Dim rsPhone As Recordset
Dim h As Integer
Dim aResults()
Set dbDatabase = OpenDatabase("G:\OMR\MRM\_MARS\1. Management & Admin\Phone List\phone book database.mdb")
Set rsPhone = dbDatabase.OpenRecordset("addresses", dbOpenSnapshot)
h = 0
With rsPhone
Do Until .EOF
ComboBox2.AddItem (h)
ComboBox2.Column(0, h) = .Fields("Firstname") & " " & .Fields("Lastname")
.MoveNext
h = h + 1
Loop
End With

End Sub
------------------------------------------

It call the data from the first and last names in the database. it also pick up inactive users. So i need to add information for the record active
If Active=yes
so it only pick current users on the list.

This is a good work around if you need more than 25 names on the combobox.

Never give up never give in.

There are no short cuts to anything worth doing :)
 
Code:
Private Sub UserForm_Initialize()
  Dim dbDatabase As [red]DAO.[/red]Database
  Dim rsPhone As [red]DAO.[/red]Recordset
  Dim h As Integer
[red]  Dim strMDB as String
  Dim strSQL as String
  strSQL = "SELECT FirstName, LastName FROM Addresses WHERE Active " & _
    "ORDER BY LastName, FirstName
  strMDB = "G:\OMR\MRM\_MARS\1.  Management & Admin\Phone List\phone book database.mdb"[/red]
  Dim aResults()
  Set dbDatabase = OpenDatabase([red]strMDB[/red])
  Set rsPhone = dbDatabase.OpenRecordset([red]strSQL[/red], dbOpenSnapshot)
  h = 0
  With rsPhone
    Do Until .EOF
      ComboBox2.AddItem (h)
      ComboBox2.Column(0, h) = .Fields("Firstname") & " " & .Fields("Lastname")
      .MoveNext
      h = h + 1
    Loop
  End With

End Sub

Duane
Hook'D on Access
MS Access MVP
 
Sorry for delay I gave it a go but still not working. Also sorry the active field is a true false and not yes no as I stated. Again thanks for your input

Never give up never give in.

There are no short cuts to anything worth doing :)
 
In access/vb there is actually no difference in a yes/no, true/false field. They are just boolean fields. A boolean field stores -1 (true, yes) or 0 (false, no). The true/false,yes/no, etc are just formats on the field. So that is not an issue.

Please be descriptive of what happens. There is a big difference between "it crashed my computer and flames shot out", "it gives a run time error and the message is ...", or "it provides data but ...". "not working" does not allow us to help.
 
MajP Thank you yes you are right about -1 or 0 . The code in my case is in MS Word 2003, that is calling the database. The problem which is now working part way. USING THE FOLLOWING (WHERE aCTIVE =TRUE)this works for only showing active people on the list. So still have not figured out the sort yet.

Thanks for getting back with the information

Never give up never give in.

There are no short cuts to anything worth doing :)
 
Does not matter it is still vba. In vb the following are all the same
Where Active = True
Where Active = -1

Please post your Sql string as you wrote it.
 
Joeatwork,

Yes it may be some fun trying to work this one out. The combo box is populated with names (first and last) from the database. The problem is that thet are in the order in the database and not sorted a-z. I think my problem is do I store the data and sort it and then add to combo box is is there an easier way to have an alpha list in the combo box. Thanks

Never give up never give in.

There are no short cuts to anything worth doing :)
 
No, you simply return an ordered query as your recordset. Duane's code should have done that, so we need to see your SQL to see what you are doing wrong. Please post all of your code for this.
 
Thank you MajP and Duane. I changed the sort to first name and it works well. Again thank for ALL you assistance, it got me out of a lot of issues.

Never give up never give in.

There are no short cuts to anything worth doing :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top