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 8th, 2002, 05:00 PM   #1
MrBaldGuy
New Member
 
Join Date: Mar 2002
Posts: 4
Default

I downloaded an excel file that demonstrated the use of a userform inserting, deleting, and editing records in a database. When I activated the code in the file that I downloaded, all worked well. I had another project that I am working on and this looked like the perfect code that I needed to perform the above in my file. After copying the code from the downloaded file to my module (and not having it to work) and then typing in the code, and still not having it to work, I decided it was time I seeked help from the masters. The following is the subroutine I have been trying to call.

Sub GetData()
With Me
.TextA = Range("Database").Cells(iRowNumber, 1)
.TextB = Range("Database").Cells(iRowNumber, 2)
.TextC = Range("Database").Cells(iRowNumber, 3)
.TextD = Range("Database").Cells(iRowNumber, 4)
End With
End Sub

When the above sub is called, I always receive the error: Run-time error '1004'
Application-defined or object-defined error.

Oh yes, by the way, my module begins with...
Option Explicit
Dim iRowNumber As Integer.

I have checked spelling, and everything seems to correspond with the downloaded file, but I keep getting the error.

Any help would be greatly appreciated.
MrBaldGuy
MrBaldGuy is offline   Reply With Quote
Old Mar 8th, 2002, 05:06 PM   #2
gplhl
Board Regular
 
Join Date: Feb 2002
Location: Chippenham, UK
Posts: 136
Default

Do you have a named range setup called Database?

_________________
Regards,

Gary Hewitt-Long

[ This Message was edited by: gplhl on 2002-03-08 16:06 ]
gplhl is offline   Reply With Quote
Old Mar 8th, 2002, 05:07 PM   #3
Russell Hauf
MrExcel MVP
 
Russell Hauf's Avatar
 
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
Default

You're going to have to give more information. Start by posting the whole Subroutine, not just part of it. For example, where is iRowNumber being set? If it's not, that's a big problem.

Also, are there text boxes in your form named TextA, TextB, TextC, and TextD? Is there a range in your spreadsheet called "Database"?

Thank you,

-rh
Russell Hauf is offline   Reply With Quote
Old Mar 8th, 2002, 05:12 PM   #4
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-08 16:00, MrBaldGuy wrote:
I downloaded an excel file that demonstrated the use of a userform inserting, deleting, and editing records in a database. When I activated the code in the file that I downloaded, all worked well. I had another project that I am working on and this looked like the perfect code that I needed to perform the above in my file. After copying the code from the downloaded file to my module (and not having it to work) and then typing in the code, and still not having it to work, I decided it was time I seeked help from the masters. The following is the subroutine I have been trying to call.

Sub GetData()
With Me
.TextA = Range("Database").Cells(iRowNumber, 1)
.TextB = Range("Database").Cells(iRowNumber, 2)
.TextC = Range("Database").Cells(iRowNumber, 3)
.TextD = Range("Database").Cells(iRowNumber, 4)
End With
End Sub
1) Have you defined the Named range "DataBase" ?
2) What about your Textboxs have these been
named as TextA, TextB etc


Ivan

Ivan F Moala is offline   Reply With Quote
Old Mar 8th, 2002, 09:58 PM   #5
MrBaldGuy
New Member
 
Join Date: Mar 2002
Posts: 4
Default

Thanks guys, the following is the code I am working with. I do have named ranges in a worksheet for all references to ranges in the code. Thanks again.

Option Explicit
Dim iRowNumber As Integer

Private Sub btnRestore_Click()
Call GetData
btnRestore.Enabled = False
End Sub

Private Sub CommandButton1_Click() 'new record
Call PutData
Range("Database").Resize(Range("Database").Rows.Count + 1).Name = "Database"
iRowNumber = Range("Database").Rows.Count
Call GetData
TextA.SetFocus
ScrollBar1.Max = Range("Database").Rows.Count
ScrollBar1.Value = iRowNumber
btnRestore.Enabled = False
lblRecNumber.Caption = iRowNumber - 1
End Sub

Private Sub CommandButton2_Click()
If Range("Database").Rows.Count = 2 Then
MsgBox "You cannot delete the last record", vbExclamation
Exit Sub
End If
If MsgBox("Are you sure you want to delete this record?", vbQuestion + vbOKCancel) = vbCancel Then
Exit Sub
Range("Database").Rows(iRowNumber).EntireRow.Delete
If iRowNumber > Range("Database").Rows.Count Then
iRowNumber = Range("Database").Rows.Count
End If
Call GetData
ScrollBar1.Enabled = False
ScrollBar1.Value = iRowNumber
ScrollBar1.Max = Range("Database").Rows.Count
lblRecNumber.Caption = iRowNumber - 1
End Sub

Private Sub CommandButton4_Click()
Unload Me
End Sub

Private Sub ScrollBar1_Change()
Call PutData
iRowNumber = ScrollBar1.Value
btnRestore.Enabled = False
Call GetData
TextA.SetFocus
lblRecNumber.Caption = iRowNumber - 1
End Sub

Private Sub TextA_Change()
Me.EditEntry
End Sub

Private Sub TextB_Change()
Me.EditEntry
End Sub

Private Sub TextC_Change()
Me.EditEntry
End Sub

Private Sub TextD_Change()
Me.EditEntry
End Sub

Private Sub UserForm_Activate()
iRowNumber = Range("lastRecordNumber")
If iRowNumber > Range("Database").Rows.Count Then
iRowNumber = Range("Database").Rows.Count
End If
Call GetData
ScrollBar1.Value = iRowNumber
ScrollBar1.Max = Thanks Guys, the following is the complete code I am working with. By the way, I have named ranges for those refered to in the code. Thanks again.


Range("Database").Rows.Count
btnRestore.Enabled = False
End Sub

Sub EditEntry()
btnRestore.Enabled = True
End Sub

Sub GetData()
With Me
.TextA = Range("Database").Cells(iRowNumber, 1)
.TextB = Range("Database").Cells(iRowNumber, 2)
.TextC = Range("Database").Cells(iRowNumber, 3)
.TextD = Range("Database").Cells(iRowNumber, 4)
End With
End Sub

Sub PutData()
With Me
Range("Database").Cells(iRowNumber, 1) = .TextA
Range("Database").Cells(iRowNumber, 2) = .TextB
Range("Database").Cells(iRowNumber, 3) = .TextC
Range("Database").Cells(iRowNumber, 4) = .TextD
End With
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Call PutData
Range("lastRecordNumber") = iRowNumber
End Sub


[ This Message was edited by: MrBaldGuy on 2002-03-08 21:02 ]
MrBaldGuy is offline   Reply With Quote
Old Mar 11th, 2002, 04:06 PM   #6
Russell Hauf
MrExcel MVP
 
Russell Hauf's Avatar
 
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
Default

Can you tell us where exactly the error is occuring? (when the error occurs, click the Debug button).

Thank you,

rh
Russell Hauf is offline   Reply With Quote
Old Mar 11th, 2002, 05:54 PM   #7
MrBaldGuy
New Member
 
Join Date: Mar 2002
Posts: 4
Default

The error occurs at "Call GetData" when the Private Sub UserForm_Activate routine is running. When I click on the Debug button in the dialog box, the line of code beginning with ".TextA" is highlighted. Hope this helps.
MrBaldGuy is offline   Reply With Quote
Old Mar 11th, 2002, 05:56 PM   #8
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
Default

Try it like this (The Me part is not needed IF THE CODE is in the userform module)


Sub GetData()
TextA = Range("Database").Cells(iRowNumber, 1)
TextB = Range("Database").Cells(iRowNumber, 2)
TextC = Range("Database").Cells(iRowNumber, 3)
TextD = Range("Database").Cells(iRowNumber, 4)
End Sub


_________________
Regards,

Juan Pablo G.
MrExcel.com Consulting

[ This Message was edited by: Juan Pablo G. on 2002-03-11 16:57 ]
Juan Pablo González is offline   Reply With Quote
Old Mar 11th, 2002, 06:11 PM   #9
Russell Hauf
MrExcel MVP
 
Russell Hauf's Avatar
 
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
Default

Quote:
On 2002-03-11 16:54, MrBaldGuy wrote:
The error occurs at "Call GetData" when the Private Sub UserForm_Activate routine is running. When I click on the Debug button in the dialog box, the line of code beginning with ".TextA" is highlighted. Hope this helps.
I think I know your problem. Try putting the sheet name in front of Range(...

Such as:

Sheets("Sheet1").Range("Database").Cells(iRowNumber, 1)

or

ActiveSheet.Range("Database").Cells(iRowNumber, 1)

if the active sheet is the one you're working with. The first option is probably better.

Hope this helps,

Russell

Russell Hauf is offline   Reply With Quote
Old Mar 11th, 2002, 09:58 PM   #10
MrBaldGuy
New Member
 
Join Date: Mar 2002
Posts: 4
Default

Hi again guys,
tried both solutions but neither worked. i still received the "1004" error. any other ideas? thanks again for your assistance.
MrBaldGuy 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 04:26 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