Solved

Assign recordset value to textbox

Posted on 1998-10-29
5
558 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now