vba Handling error when multiple users are using cell value in procedure - excel

Excuse me if I am asking already handled problem.
I am trying to automate the invoicing of our company.
We have an excel workbook with all the information about the clients, monthly payments and etc. I ve made the system and it works great. I even sent email with specific text and the invoice attached.
The problem comes when multiple users are using the system, so the invoice numbers duplicate.
Invoice number is stored in the excel workbook and after every invoice it becomes + 1.
The system works like this:
Login form - login with username.
The macro copies from the master table/modified protected/ only the info for the users clients and paste it into new wb template. The user checks the info, approves it and clicks send button.
Then the macro make the invoices using the number from the first wb and send the email to the client.
Do you have any tips how to protect the invoice number cell when someone is using the macro? I was thinking of making a list of users and when someone logs in his variable becomes 1, so if the sum of all users is greater than 1 you cant issue an invoice. But thats lame.
Hope there is a way like- when busy .....
But how can user 2 know that user1 is issuing.
Appreciate if you can help.

I'm not entirely clear on the exact process you're using to get the invoice number here, but it sounds like the number is being retrieved from another sheet and then incremented by one, correct?
If so, the best option might be to record each invoice as you go - as soon as the macro grabs an invoice number, it records a new line of data with the new invoice number on it. That way the next person to use the macro, even if it's only seconds later, would get the next number in the sequence, rather than the same number. The process would be something like:
lngLast = wbkOtherWorkbook.range("A" & rows.count).end(xlup).row
lngInvoiceNum = wbkOtherWorkbook.range("A" & lnglast).value +1
wbkOtherWorkbook.range("A" & lnglast+1).value = lngInvoiceNum
I'd imagine you'll want to keep a list of all your invoices somewhere anyway - just include this step in the recording process.

thank you guys, i ll try to explain better. So only I can edit the master table, everybody is opening a read only copy of the wb. The invoices after issued are saved in the coresponding folder - one for each client. The number for the invoice is the tricky part.
Today I made two possible solutions:
1. I made a function, when someone is issuing, first his own macro counts the invoices he is going to make. Then opens different /third wb/ with the invoice number, takes the value and adds the invoices count which will be made. So I only lose 1 sec or something. Also made a loop while isworkbookopen(numberInvoice)=true do events wend.
This way the number is always correct.
2. The other option I havent tested yet is sharing the trird wb /numberInvoice/ so anyone can use and manipulate it simultaniously. Dont understand if sharing a wb is going to work, but thats diffrent topic.
So I am going to take Ralph advice and I am looking forward to learn some Access database stuff. Wish you all the best!
P.S. working with vba for like a month or two, so Im kind a newb. Thank you for understanding.

Related

How to create a search function within Excel

Could somebody please help me create a search feature in Excel, intended as a contact lookup? I'm reasonably comfortable in Excel up to 2016 but have no VBA knowledge so I hope this can be done without it. Using Excel 365 and it will be published to Sharepoint to specific users. I know it's poor practice on here to rely on sample data so I'll do my best to explain with a couple of screenshots.
Situation:
I have a raw data sheet containing 50,000 rows (CustomerName, ID, City, Country, EmailAddress etc). Our sales team need to look up contact details but only if they know the customer's name, or part thereof.
I need to hide the underlying data but a rudimentary system is acceptable, we just don't want to serve it up on a platter. The basic shove-it-under-the-mattress method by making it all white text; lock all cells; hide all rows and columns; password protect and hide the sheet is fine for now - no one will be determined enough to start picking that apart.
I've searched here and while there are similar results, nothing really fits perfectly. The most suitable so far was on extendoffice which doesn't quite suffice (will put link in attachment). It utilises SEARCH, RANK, ROW and VLOOKUP functions, the interaction of which I don't entirely understand, but it works.
Interim steps for the lookup function on sheet "Search"
Issues with current concept:
There's no discernable order to the results. The RANK and ROW functions seem to randomly assign ranks, and when you get 50+ results with no way of sorting it will be frustrating.
Whenever one person queries it undoes the last person's search. Expected, but not nice
Partial string search with results unsorted
Additionally:
This doc will be on Sharepoint, directly accessible by ~20 people. Ideally, when one person searches it won't change on someone else's screen
Results should appear alphabetically by customer name
Nice to haves:
Add another criteria to search by. Eg City or Account Manager - doesn't have to stack
Select and copy the contents of a cell (eg email address), but not allow editing of the value or formula. If not possible I'll leave the cells completely locked as the trade-off of accidentally overriding a formula is not worth it.
Any help would be super appreciated

Send notification/email 7 days before given date

I have table with employees. It contains some information and also date of birth. Is it possible to send notification/email (directly from excel) let's say 7 days in advance to know that he/she will have birthday soon?
I found some tutorials, but all require Visual Basic. Unfortunately, it is for my sister without any knowledge of programming.
Yes, it is possible to do this via Word's mail merge feature. But since this would require quite a few manual steps (presumably on a daily/weekly basis), I'm afraid it's not what your sister is after. You could code a similar feature in VBA but that would still require her to open the document regularly to run the macro so perhaps it would be quicker and simpler to just check a filtered employee list.
If you want a closer look at mail merge, try this. You could use a helper column to identify which birthdays are close (e.g. using this) and filter on that column, then you show only those whose birthdays are in the next x days.

How to create exact same thing in Ms Access?

First of all i'm new to Ms Access, i have created small database of School, with students fee details in one excel sheet and the Fee Bill print template in other sheet, and linked them both so that i can print Fee Bill of each student. But at the end of each month i want to carried forward the fee details and remaining fee of each student, i have done it in excel also, but it got corrupted easily, and if i have to delete one student then i have to go through many things, So i want to create the same thing in access, i'm attaching the excel sheet for full explanation.
Excel Worksheet sample
Things i wanna do..
I want to create the same data base as the excel.
I want to create a template for printing fee bill for each student.
After every month next fee bills should be ready.
Any help will be really appreciated.
you really need to learn a bit of access first and foremost your question is extremely broad and difficult to answer, many things would go into such a task. the below should get you started.
You should first import the data you have into Access, this will give you somewhere to start with number 1.
look into a tutorial on how to produce reports in Access this will resolve number 2
look into a tutorial on how to produce forms in Access this will allow for easier input and progress towards your 3rd objective.
Hope this helps.

Trying to set up a summary sheet for data validation

I've created a workbook for a friend who owns her own business. The workbook includes a sheet for each month, with Data Validation to determine the service, price, products, etc. It also indicates a method of payment.
She's asked that I update the summary sheet to not only show the totals per month, but to also show the total for each method of payment.
I'm having a hard time finding the right way to do this. Since this could change for each client, I imagine I'll have some sort of If statement, but I don't have enough experience to be able to successfully write this out (at least not in excel).
Any help is greatly appreciated. Thanks!

fetch data from ms-access to ms-word

i am looking to create an invoice in either MS-excel or MS-word. This invoice will contain several fields like invoice no., customer name, product info, quantity, Amount, Date, Address of customer, phone no. etc. The function of the invoice will be, to generate a unique invoice number, every time i open it, and then the vendor will mention the customer's info, product's info and click on submit button or save it. The info mentioned in the invoice will automatically be saved in the MS-Access database whenever submit button is clicked or the document is saved.
Thus, All the records of the customer will be saved in the MS-Access database. whenever i need to search for a particular customer, i should be able to search it from either invoice no. or any unique field for that particular invoice. I hope my query is explained clearly. please let me know the easiest way to do it. I do not have the vast knowledge about this subject, so give me suggestions that are understandable by a Novice.
I think you are starting from the wrong end. Use an Access form to get the data and then run a mailmerge, the easiest way is to output a text file from Access as the data file and use a Word template for the merge.
An autonumber may suit for invoice number as long as all you need is a unique number. If you need documented sequential numbers, you will have to create then yourself. How you do it will depend on the number of users working at the same time.
I can tell you now, generating Word files with Access is a bit of a pain in the ass. If you really want to do formatting it gets hard (is my experience).
I ended up generating HTML files in which I could control everything, and opening them as .docs. But if you are really new to this, I suggest you start with some VBA tutorials, where they explain to you how you get records from you database and loop through them to generate output. And then you can start looking at file writing functions in VBA.
Can't find any tutorials real quick (my girlfriend is getting angry as we speak), but here is a sample:
http://www.access-programmers.co.uk/forums/showthread.php?t=25354
Just look around in fora, look for file generation and looping through records.
Hi just reading your post, like Remou l would strongly suggest you use Access to enter and store the data. It is possible to get a user to enter data into a spreadsheet and write the data back to Access DB. Not something l would recommend for the novice, here is a link to some code on how it could be done
Returning to your first question, of creating the invoice have you considered generating the invoices from Access using a report? They can be printed to PDF, or exported to various electronic formats. Or is there specific reason to use Word/Excel? If are going down the route of using Word to generate the invoice then use a template as Remou suggested. See this link for some samples see the section titled Access > Word. I have used the examples as a basis for Access to Word. A number of the examples though use a tecnology called DAO, which l understand will not be included in any operating system after Windows 7. Just something to be aware of.
Searching for a record in a database table this link has one possible solution . Also the author has included a example database.

Resources