Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Assign recordset value to textbox

Posted on 1998-10-29
5
578 Views
Last Modified: 2013-12-25
Table: cmhc
fields: name, cmhcno

In the form load event,  I populate Combo1 with the following SQL:

Dim db As Database
Dim rscmhc As Recordset
Dim SQL As String
Set db = Workspaces(0).OpenDatabase("\vb\biblio.mdb")
SQL = "Select name from cmhc order by name"
Set rscmhc = db.OpenRecordset(SQL)
rscmhc.MoveLast
rscmhc.MoveFirst
Do While Not rscmhc.EOF
Combo1.AddItem rscmhc("name")
rscmhc.MoveNext
Loop
End Sub

In a command button click event, I want to assign the value of the cmhcno field
of whatever record is currently showing in the Combo1 box to a textbox.  

Thanks

0
Comment
Question by:foxsage
5 Comments
 
LVL 2

Expert Comment

by:alokm
ID: 1497285
use findfirst with the currently selected item in the combo so that recordset points to that particular record.
then assigh whatever field u want to the textbox.
hope it helps,
Alok
0
 
LVL 2

Expert Comment

by:vspeter
ID: 1497286
TextBox.Text = Combo.List(Combo.ListIndex)
0
 

Author Comment

by:foxsage
ID: 1497287
this works fine, except the value I want to assign is not the same value in Combo1.  The Combo1 value is 'name'. The value I want to assign to the textbox is 'cmhc', a field in the same record.
0
 
LVL 3

Accepted Solution

by:
TheAnswerMan earned 0 total points
ID: 1497288
sub combo1_click
 dim lr_rec as recordset
 dim ls_SQL as string
 ls_SQL = "SELECT MyOtherField FROM CMHC WHERE Name = '" &  combo1.text & "'"
 Set lr_rec = db.OpenRecordset(SQL)
 if not lr_Rec.EOF then textbox1 = lr_Rec!MyOtherField & ""
end sub
0
 
LVL 1

Expert Comment

by:can9999
ID: 1497289
'// you must declare global for common.
Dim rscmhc as Recordset
Dim iRecCnt% 'Record Number      

Dim lret& 'Temp Value

Private Sub Command1_Click()
Dim sSql$

  ' Check blank in Combo1
  if trim(Combo1.Text) = "" then
      lret = msgbox("Choose Name", vbCritical)
      exit sub
  endif

  sSql = "SELECT cmhcno FROM cmhc WHERE name = '" & _             trim(Combo1.text) & "'"
  Set rscmhc = db.OpenRecordset(sSql)

  if rscmhc.recordcount = 0 then
        lret = msgbox("There is no rec", vbInformation)
      exit sub
  endif

  text1.text = rscmhc.fields("cmhcno")

  lret = msgbox ("GOOD JOB !", vbExclamation)

End Sub
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question