Solved

Assign recordset value to textbox

Posted on 1998-10-29
5
542 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
Comment Utility
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
Comment Utility
TextBox.Text = Combo.List(Combo.ListIndex)
0
 

Author Comment

by:foxsage
Comment Utility
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
Comment Utility
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
Comment Utility
'// 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

17 Experts available now in Live!

Get 1:1 Help Now