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

x
?
Solved

DBCombo Box

Posted on 1997-11-22
7
Medium Priority
?
394 Views
Last Modified: 2008-03-06
Hi all,

I'm using visual basic 4. My program contains 2 forms and one module. Form1 has a DBCombo box style 1, a Data Control which is connected with the DBCombo and my access file and a command button. Form2 has few text boxes  and a Data Control with the necessary connection between it and the text boxes and my access file.

In the lower portion of my DBCombo in Form1 a list of movie titles are displayed from my access file. The user will type the title he is looking for in the upper portion of the DBCombo and the list of titles will automatically scroll down according to what the user types (that is because it's style 1). Once the title have been allocated in the list I then want my program to display information of that particular title in the text boxes in form2 when the user clicks on the command button in Form1.  This is the code I have come up with so far:

First I type the following in my module

      Public varname
      Public MovieName
      Public Count
      Count = 0

Second I typed the following in my button command click

      MovieName = Combo1.Text
      load form2
      form2.show
      Count = 1

Finally I typed the following in my Form2 load

If count = 0 then
Data1.RecordSource = varname
Else
data1.recordset.findfirst "fieldname =" & "'" & MovieName & "'"
count = 0

However when I try running my program I get an Error message saying "Invalid Outside Procedure" on the zero in the statement "count = 0" in the module. What am I doing wrong? And does anyone have any better ideas on how to make my DBCombo work? Your help is appreciated! :)

Thanx
Belle
0
Comment
Question by:Belle
[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
  • 4
  • 3
7 Comments
 
LVL 5

Accepted Solution

by:
dirtdart earned 100 total points
ID: 1442094
You can't directly set values of variables in the General Declarations section of a module.  If Form1 is your main form, place your Count = 0 in the Form_Load event of Form1.

As far as how your DBCombo works, it looks pretty good to me except that I don't like using data bound controls, but that's just personal opinion.
0
 

Author Comment

by:Belle
ID: 1442095
Hi again,

I Placed Count = 0 in the form_load of my form1 but when I tried running my program I got an error at the "count =" which I have just placed in the form_load with a message saying "Function call on the left-hand side of assignment must return Variant or Object". I'm not really sure what's that asking me to do. Can you help?

Thanx
Belle

0
 
LVL 5

Expert Comment

by:dirtdart
ID: 1442096
I see the problem now.  Count is a reserved word.  I'm not sure exactly what it refers to, but VB won't let you use it.  Pick another variable name (I usually use ct for counters) and declare  it public in your module, then do a find and replace in the rest of  your code, and you should be alright.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Belle
ID: 1442097
Hi again,

Umm sorry I'm new at Visual Basic, I did change my variable name to cntr but when I run my program now and click on the command button in Form1 I get nothing in my text boxes in Form2 other than their names (Text1, Text2 and so on). It's not retrieving the data of that specific Title the user chose from the DBCombo for some reason, and I'm not so sure what you ment by "do a find" and how it is done, can you direct me some more if it's not so much trouble, thanx :)

Belle
0
 
LVL 5

Expert Comment

by:dirtdart
ID: 1442098
By do a find and replace, I just meant click on the Edit menu, then click Find and Replace.  Basically, just make sure all instances of Count are replaced with your new variable.  Find and Replace is just the easiest way to do that.  Just like in a word processor.

I notice that you didn't set the DataSource and DataField properties of your text boxes.  That's probably why you didn't get any information. If you are setting the Data1.DataSource at runtime, and not the Text1.DataSource and Text1.DataField, then the text box doesn't know which field to bind to.  DataSource would be Data1, and DataField would be whatever field in the data source that you are trying to display.
0
 

Author Comment

by:Belle
ID: 1442099
I may have not included the setting of the text1.datasource and the text1.datafield in my code but I have set them in the properties window of the text boxes so I'm still trying to figure out why it won't display the data from my access file in form2.
0
 
LVL 5

Expert Comment

by:dirtdart
ID: 1442100
If you'd like, zip up your project and send it to me at dirtdart@apex.net.  I'll take a look at it for you.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…
Suggested Courses

636 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