Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Assign recordset value to textbox

Posted on 1998-10-29
5
Medium Priority
?
621 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses

604 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