Solved

Assign recordset value to textbox

Posted on 1998-10-29
5
589 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
[X]
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
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

730 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