Solved

DBCombo Box

Posted on 1997-11-22
7
384 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 Compile Compatibility Issue 4 121
MS Access Search and Replace Using VBA 6 92
Adding to a VBA? 6 83
Access2016 ignore hyphen in data entry or searches 5 41
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…
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 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…
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…

685 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