MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 27th, 2002, 08:30 AM   #1
slimpickens
New Member
 
Join Date: Feb 2002
Posts: 35
Default

Hi guys & gals

I have written some code for my worksheet but I keep getting the above error message. I have tried using Help to see if I can get it sorted out but I am not getting anywhere. Most of the code I found in a visual basic manual and I changed it around to suit my purposes but since I have limited knowledge of VB, I find myself at a loss. Would anyone care to have a look at the code and probably point me in the right direction????


Drop me a line:- Randycas@yahoo.com
slimpickens is offline   Reply With Quote
Old Mar 27th, 2002, 08:35 AM   #2
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
Default

I think you could have better results if you posted the not working code and tell us where exactly is it showing the error.
__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González is offline   Reply With Quote
Old Mar 27th, 2002, 09:49 AM   #3
slimpickens
New Member
 
Join Date: Feb 2002
Posts: 35
Default

I posted all the code since the line that is giving the problem is

""#gFileNum, gCurrentRecord, gPerson""

This goes throughout the coding


Dim w As Workbook
Dim gPerson As PolicyInfo
Dim gFileNum As Integer
Dim gRecordLen As Long
Dim gCurrentRecord As Long
Dim gLastRecord As Long


Public Sub SaveCurrentRecord()
'Fill gPerson with the currently displayed data
gPerson.Polno = Polno.Text
gPerson.Refno = Refno.Text
gPerson.Action = Action.Text
gPerson.Comments = Comments.Text

'Save gPerson to the current record
Put #gFileNum, gCurrentRecord, gPerson

End Sub
Public Sub ShowCurrentRecord()
'Fill gPerson with data of current record
Get #gFileNum, gCurrentRecord, gPerson

'Display gPerson
Polno.Text = Trim(gPerson.Polno)
Refno.Text = Trim(gPerson.Refno)
Action.Text = Trim(gPerson.Action)
Comments.Text = Trim(gPerson.Comments)

'Display the current record number in the caption of the form

Cancellations.Caption = "Record " + _
Str(gCurrentRecord) + "/" + _
Str(gLastRecord)

End Sub
Private Sub Form_Load()
'Calculate the length of the record
gRecordLen = Len(gPerson)
'Get the next available file number
gFileNum = FreeFile

'Open the file for random access. If the file
'does not exist then it is created.

Open "CANCELLATIONS" For Random As gFileNum Len = gRecordLen

'Update gCurrentRecord.
gCurrentRecord = 1

'Find what is the last record number of the last record

gLastRecord = FileLen("CANCELLATIONS.XLS") / gRecordLen

'If the file was just created, the update gLastRecord to 1

If gLastRecord = 0 Then
gLastRecord = 1
End If

'Display Current Record
Show CurrentRecord

End Sub

Private Sub Action_Enter()
ActiveControl.DropDown

End Sub

Private Sub cmdExit_Click()
'Save the current record
SaveCurrentRecord
'Close the File
Close #gFileNum
For Each w In Application.Workbooks
w.Save
Next w
Application.Quit

End

End Sub

Private Sub cmdNew_Click()
'Save the current record
SaveCurrentRecord
'Add a new blank record
gLastRecord = gLastRecord + 1
gPerson.Polno = ""
gPerson.Refno = ""
gPerson.Action = ""
gPerson.Comments = ""


'Update gCurrentRecord
gCurrentRecord = gLastRecord

'Display the record that was just created.
ShowCurrentRecord

'Give the focus to the txtName field.
Polno.SetFocus

End Sub
Private Sub cmdNext_Click()
'If the current record is the last record,
'beep and display an error message. Otherwise,
'save the current record and skip to the
'next record.

If gCurrentRecord = gLastRecord Then
Beep
MsgBox "End of File!", vbExclamation
Else
SaveCurrentRecord
gCurrentRecord = gCurrentRecord + 1
ShowCurrentRecord
End If
'Give focus to the polno field
Polno.SetFocus

End Sub
Private Sub cmdPrevious_Click()
'If the current record is the first
'beep and display an error message. Otherwise
'save the current record and go the the previous record
If gCurrentRecord = 1 Then
Beep
MsgBox "Beginning of File!", vbExclamation
Else
SaveCurrentRecord
gCurrentRecord = gCurrentRecord - 1
ShowCurrentRecord
End If
Polno.SetFocus

End Sub


Private Sub cmdSearch_Click()
Dim NameToSearch As String
Dim Found As Integer
Dim RecNum As Long
Dim TmpPerson As PolicyInfo

'Get the name to search from the user
NameToSearch = InputBox("Search for:", "Search")

'If the user did not enter a name, exit from this procedure
If NameToSearch = "" Then
'Give the focus to the polno.
Polno.SetFocus
'Exit this porcedure.
Exit Sub
End If

'Convert the name to be searched to upper case.
NameToSearch = UCase(NameToSearch)

'Initialize the Found flag to False
Found = False

'Search for the name the user entered.

For RecNum = 1 To gLastRecord
Get #gFileNum, RecNum, TmpPerson
If NameToSearch = UCase(Trim(TmpPerson.Refno)) Then
Found = True
Exit For
End If
Next

'If the name was found, display the record of the found name

If Found = True Then
SaveCurrentRecord
gCurrentRecord = RecNum
ShowCurrentRecord
Else
MsgBox NameToSearch + " not found!"
End If
'Give the focus to the Polno
Polno.SetFocus

End Sub
slimpickens is offline   Reply With Quote
Old Mar 27th, 2002, 10:34 PM   #4
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Hi Slimpickens

how have you configured the code to run ?
and is this the complete code.

the reason i ask is that this is obviously
VB code and is designed to run similar to
a VBA Userform eg.

Private Sub Form_load()

VBA eq Private Sub UserForm_Initialize()

Running the code via a userform ini would
set up your defined Freefile variable.

But I think you are also missing some Data Type declarations as you have;
Dim gPerson As PolicyInfo but have no
declarations for this

would suggest that there should be something
along these lines....

Private Type PolicyInfo
Polno As String
Refno As String
Action As String
Comments As String
End Type


Post for further help and how you have configured this to run.

Ivan
Ivan F Moala is offline   Reply With Quote
Old Mar 28th, 2002, 09:57 AM   #5
slimpickens
New Member
 
Join Date: Feb 2002
Posts: 35
Default

Thanks for the help Ivan,

I made declarations for PolicyInfo , I have them in a module, do I need to move them.

I am not quite sure what you mean by "configuring the code" since I copied the code from a book, just making some adjustments. I really have absolutely no idea what is going on when coding starts to get really technical but I am trying to learn. Though it is hard. I have been trying to find a manual which deals directly with excel and Vb, but the bookstores here do not have any.

I will try the code for the Intialize event and see what happens, while I wait to locate a manual.

Carol

slimpickens is offline   Reply With Quote
Old Mar 28th, 2002, 02:03 PM   #6
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
On 2002-03-28 08:57, slimpickens wrote:
Thanks for the help Ivan,

I made declarations for PolicyInfo , I have them in a module, do I need to move them.

I am not quite sure what you mean by "configuring the code" since I copied the code from a book, just making some adjustments. I really have absolutely no idea what is going on when coding starts to get really technical but I am trying to learn. Though it is hard. I have been trying to find a manual which deals directly with excel and Vb, but the bookstores here do not have any.

I will try the code for the Intialize event and see what happens, while I wait to locate a manual.


Hi Carol
Have you used this code for a Userform ?
Thats what the code was designed for.

When I said configure I meant adjusted.
As I said before this code was meant for
a VB Form and there are slight diff in VB
and VBA syntax.

The Type declarations should reside in the
same Module / userform as the code you gave
above.

Ivan

Post if you require assistance
Ivan F Moala is offline   Reply With Quote
Old Apr 8th, 2002, 01:59 PM   #7
slimpickens
New Member
 
Join Date: Feb 2002
Posts: 35
Default

I will try that and get back to you Ivan. Sorry I took so long to answer, but we were having some problems with the Internet here at work.

Carol
slimpickens is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 07:23 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes