Solved

DBCombo Box

Posted on 1997-11-22
7
376 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
  • 4
  • 3
7 Comments
 
LVL 5

Accepted Solution

by:
dirtdart earned 50 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

744 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

10 Experts available now in Live!

Get 1:1 Help Now