473,396 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

search VBA code from button-click on Form

I have a form that lists several different categories for labels. I
made a form that will let the user add a new category. On the Form the
user can type in the name for the new category, then I thought I would
search the code below and replace "ReservedForNewCategory01" (or the
next available category, possibly "ReservedForNewCategory02"), with the
name of the new category that the user typed into the Form. How can I
search and replace the VBA code from the button-click on the Form?

While lngBooks > 0
If lngBooks >= 1 Then
strCategory = "Books"
strCategorySpanish = "Libros"
dblPriceUS = 50
dblPriceBolivia = 0.5
Call BarCodeLabelMakerFormPrintButton_Click
lngBooks = (lngBooks - 1)
End If
Wend

While lngReservedForNewCategory01 > 0
If lngReservedForNewCategory01 >= 1 Then
strCategory = "Books"
strCategorySpanish = "Libros"
dblPriceUS = 50
dblPriceBolivia = 0.5
Call BarCodeLabelMakerFormPrintButton_Click
lngReservedForNewCategory01 = (lngReservedForNewCategory01 - 1)
End If
Wend

While lngReservedForNewCategory02 > 0
If lngReservedForNewCategory02 >= 1 Then
strCategory = "Books"
strCategorySpanish = "Libros"
dblPriceUS = 50
dblPriceBolivia = 0.5
Call BarCodeLabelMakerFormPrintButton_Click
lngReservedForNewCategory02 = (lngReservedForNewCategory02 - 1)
End If
Wend

Nov 13 '05 #1
2 2563
It is not at all clear to me what you are trying to _accomplish_ with what
you describe (that is, you describe how you are thinking to go about it, not
what you are trying to do). Assuming a user types in a new category, say
"Shoes", and you changed this VBA so that "lngReservedForNewCategory01"
reads "lngShoes", there won't be a value in "lngShoes", so the code wouldn't
execute, in any case . . . unless there are details you haven't included.

I suspect there is a simpler way to accomplish what you want to do, if only
we knew what that is. (That's based on almost 50 years in the software
business, during which time I have observed that "there is almost always a
better way to accomplish any given thing than changing code 'on the fly'".)

Larry Linson
Microsoft Access MVP

<rc*********@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I have a form that lists several different categories for labels. I
made a form that will let the user add a new category. On the Form the
user can type in the name for the new category, then I thought I would
search the code below and replace "ReservedForNewCategory01" (or the
next available category, possibly "ReservedForNewCategory02"), with the
name of the new category that the user typed into the Form. How can I
search and replace the VBA code from the button-click on the Form?

While lngBooks > 0
If lngBooks >= 1 Then
strCategory = "Books"
strCategorySpanish = "Libros"
dblPriceUS = 50
dblPriceBolivia = 0.5
Call BarCodeLabelMakerFormPrintButton_Click
lngBooks = (lngBooks - 1)
End If
Wend

While lngReservedForNewCategory01 > 0
If lngReservedForNewCategory01 >= 1 Then
strCategory = "Books"
strCategorySpanish = "Libros"
dblPriceUS = 50
dblPriceBolivia = 0.5
Call BarCodeLabelMakerFormPrintButton_Click
lngReservedForNewCategory01 = (lngReservedForNewCategory01 - 1)
End If
Wend

While lngReservedForNewCategory02 > 0
If lngReservedForNewCategory02 >= 1 Then
strCategory = "Books"
strCategorySpanish = "Libros"
dblPriceUS = 50
dblPriceBolivia = 0.5
Call BarCodeLabelMakerFormPrintButton_Click
lngReservedForNewCategory02 = (lngReservedForNewCategory02 - 1)
End If
Wend

Nov 13 '05 #2
Thanks for your reply. I agree that there must be a better way to do
this than changing code on the fly. I have a Form where the user can
input the number of labels they want to print for each category, for
example ten labels for books, 6 labels for shoes, etc. There are 24
categories and I want to make it possible for the user to create a new
category instead of getting a database programmer involved every time
they want a new category. On the Form there is a textbox and label for
each category and a textbox for the total. The user types the number
of labels wanted in each texbox. I could add some extra textboxes and
labels that are reserved for new categories and make them invisible
until the user needs them. But each category is hard-coded in the VBA
code (see below). Do you think I should re-write the while-wend part
so that it pulls the data for each category from a table has the data
for each category? For example, something like
strCategorySpanish = DLookup("CategoryNameSpanish", "CategoriesTable",
"RowID = Books") ?
I included more of the code below.

Public Sub BarCodePrintCategories_Click()
Dim lngBooks As Long
Dim lgnNewRecords As Long

lgnNewRecords = (Nz(TotalLabelsNumberBox, 0))

' The line below is repeated for each category
lngBooks = (Nz(BooksNumberBox, 0))

' the while-wend statement below is reapeated for each category
While lngBooks > 0
If lngBooks >= 1 Then
strCategory = "Books"
strCategorySpanish = "Libros"
dblPriceUS = 50
dblPriceBolivia = 0.5
Call BarCodeLabelMakerFormPrintButton_Click
lngBooks = (lngBooks - 1)
End If
Wend

Dim MyDB As Database, MyRecords As Recordset, Total As Long
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set MyRecords = MyDB.OpenRecordset("Products")
MyRecords.MoveLast
Total = MyRecords.RecordCount
Dim intPrintStartNumber As Long
Dim strLabelReportName As String
intPrintStartNumber = (Total - lgnNewRecords)
intPrintStartNumber = (intPrintStartNumber + 1)
strLabelReportName = "ReportForPrintingBarcodeLabels"
Application.Echo False
DoCmd.SelectObject acReport, strLabelReportName, True
'###################
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
If lgnNewRecords = 1 Then
Msg = "Is it OK to print " & lgnNewRecords & " label ?" ' Define
message.
Else: Msg = "Is it OK to print " & lgnNewRecords & " labels ?" '
Define message.
End If
Style = vbYesNo + vbQuestion + vbDefaultButton2 ' Define buttons.
Title = " OK to Print Labels?" ' Define title.
Response = msgbox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
DoCmd.PrintOut acSelection, intPrintStartNumber, Total
End If
DoCmd.OpenForm "BarCodeLabelMakerForm"
Application.Echo True
End Sub

Private Sub BarCodeLabelMakerFormPrintButton_Click()
Dim dbs As DAO.Database
Dim rs As DAO.Recordset
Dim lngNewRecords As Long
Dim lngCount As Long

Set dbs = CurrentDb()
Set rs = dbs.OpenRecordset("Products")
lgnNewRecords = (Nz(TotalLabelsNumberBox, 0))

Dim intLarge As String
Dim intLargest As String

intLarge = DMax("BoxNumber", "Products")
intLargest = (intLarge + 1)

strADDAsterisks = Eval(intLargest)
rs.AddNew
rs.Fields("BoxNumber") = (intLarge + 1)
rs.Fields("ItemCategoryNameProducts") = strCategory
rs.Fields("ItemCategoryNameProductsSpanish") =
strCategorySpanish
rs.Fields("PriceUS") = dblPriceUS
rs.Fields("PriceBolivia") = dblPriceBolivia
rs.Update
Set rs = Nothing
Set dbs = Nothing
End Sub

Larry Linson wrote:
It is not at all clear to me what you are trying to _accomplish_ with what
you describe (that is, you describe how you are thinking to go about it, not
what you are trying to do). Assuming a user types in a new category, say
"Shoes", and you changed this VBA so that "lngReservedForNewCategory01"
reads "lngShoes", there won't be a value in "lngShoes", so the code wouldn't
execute, in any case . . . unless there are details you haven't included.

I suspect there is a simpler way to accomplish what you want to do, if only
we knew what that is. (That's based on almost 50 years in the software
business, during which time I have observed that "there is almost always a
better way to accomplish any given thing than changing code 'on the fly'".)

Larry Linson
Microsoft Access MVP

<rc*********@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I have a form that lists several different categories for labels. I
made a form that will let the user add a new category. On the Form the
user can type in the name for the new category, then I thought I would
search the code below and replace "ReservedForNewCategory01" (or the
next available category, possibly "ReservedForNewCategory02"), with the
name of the new category that the user typed into the Form. How can I
search and replace the VBA code from the button-click on the Form?

While lngBooks > 0
If lngBooks >= 1 Then
strCategory = "Books"
strCategorySpanish = "Libros"
dblPriceUS = 50
dblPriceBolivia = 0.5
Call BarCodeLabelMakerFormPrintButton_Click
lngBooks = (lngBooks - 1)
End If
Wend

While lngReservedForNewCategory01 > 0
If lngReservedForNewCategory01 >= 1 Then
strCategory = "Books"
strCategorySpanish = "Libros"
dblPriceUS = 50
dblPriceBolivia = 0.5
Call BarCodeLabelMakerFormPrintButton_Click
lngReservedForNewCategory01 = (lngReservedForNewCategory01 - 1)
End If
Wend

While lngReservedForNewCategory02 > 0
If lngReservedForNewCategory02 >= 1 Then
strCategory = "Books"
strCategorySpanish = "Libros"
dblPriceUS = 50
dblPriceBolivia = 0.5
Call BarCodeLabelMakerFormPrintButton_Click
lngReservedForNewCategory02 = (lngReservedForNewCategory02 - 1)
End If
Wend


Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John | last post by:
Greetings, all, Several days after adding personalized URLs to my "amazing" collection of "God Loves (yourname)" mazes, it occurred to me that if someone were to create an offcolor term, then...
1
by: Mike | last post by:
I have a search page that I want to enable private caching so that when a user hits the back button they dont get the page has expired error. I have seen this done on: ...
2
by: Peter Morris [Droopy eyes software] | last post by:
Hi all I want to put a google search on my website. My options are 1) Create a new <form> outside of my aspx form. Problem: I have a HeaderControl and FooterControl on each page to give my...
0
by: porky008 | last post by:
I have this search button working for the most part. I would like it if some one could take a look at it and let me know what I am doing wrong it though. Basically I want it to display movie not...
3
by: Richard S | last post by:
CODE: ASP.NET with C# DATABASE: ACCES alright, im having a problem, probably a small thing, but i cant figure out, nor find it in any other post, or on the internet realy (probably cuz i wouldnt...
8
by: alive84 | last post by:
Hi there I have wrote a little script, that is used to search specific values that the User tips in. Private Sub cmdSearch_Click() Dim LSQL As String Dim LSearchString As String
13
by: jfarthing | last post by:
Hi everyone! I am using the script below to search a db. If the is more than one match in the db, all goes well. But if there is only one match in the db, nothing gets displayed. Any...
22
by: GoodGirl | last post by:
Hi : I would like to ask about : how can I write the (simplist) code for search button. I'm bignner in using Access 2007 & VBA . This button will search by name in a query which contains all...
9
by: weirdguy | last post by:
Hello, Just for anyone information, there is a similar title "Search in Listbox" but it is via Combo Box. In case, anyone need it, I put a link to here. Please let me know if I break any rules...
0
by: Mark112 | last post by:
Hi I am attempting to restore the search feature that was created by an external company using the indexing service for our intranet. the intranet is located locally at each of our offices. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.