473,394 Members | 1,699 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,394 software developers and data experts.

access 2010 vba help

hi,

i need help im new to access, vba, sql,... and need to adapt this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Project_Number_Click()
  2. If Me.Town.Column(2) = "" Or Me.Type.Column(2) = "" Then
  3. Me.Project_Number = ""
  4. Else
  5. Me.Project_Number = Me.Town.Column(2) & "-" & Me.Type.Column(2) & "-" & Me.Form.CurrentRecord
  6. End If
  7. End Sub
to actually check for which number to use for that type of project in that town.

so instead of "Me.Form.CurrentRecord"

it should check the "Towns" table where in the "Column(3)" line = "Me.Town.Column(2)" for column in that line = "Me.Type.Column(2)" and add +1

thanks for helping :)
Mar 30 '15 #1
9 1725
twinnyfo
3,653 Expert Mod 2GB
First, it seems very strange that you would be using the values of a Combo box, rather than the index. Using the index is a much more proper way of doing things, and I can only presume that since you are looking at the value of the third column that the first column is (or should be) the index. The engine behind access works much more efficiently when using indexes, which is why they exist.

Second, the statement
it should check the "Towns" table where in the "Column(3)" line = "Me.Town.Column(2)" for column in that line = "Me.Type.Column(2)" and add +1
doesn't wuite make any sense to me.

Again, if you are using an index the value of the combo box should be the same as if you looked it up in the Towns table.

I am also confused as to why you are adding one to the "Type" value.
Mar 30 '15 #2
i came up with this but it keeps giving me 001

Expand|Select|Wrap|Line Numbers
  1. Private Sub Numéro_du_projet_Click()
  2. Compteur = Nz(DMax("Séquence", "Projets", "Localité=" & Me.Localité & " and " & "Type=" & Me.Type), 0) + 1
  3. Me.Numéro_du_projet = Me.Localité.Column(2) & "-" & Me.Type.Column(2) & "-" & Format(Compteur, "000")
  4. End Sub
  5.  
Apr 2 '15 #3
this is what i have so far

Expand|Select|Wrap|Line Numbers
  1. Private Sub Numéro_du_projet_Click()
  2. If Me.Localité.Column(2) = "" Or Me.Type.Column(2) = "" Then
  3. Me.Numéro_du_projet = ""
  4. Else
  5. Compteur = Nz(DMax("Séquence", "Projets", "Localité=" & Me.Localité & " and " & "Type=" & Me.Type), 0) + 1
  6. Me.Numéro_du_projet = Me.Localité.Column(2) & "-" & Me.Type.Column(2) & "-" & Format(Compteur, "000")
  7. End If
  8. End Sub
  9.  



Apr 3 '15 #4
nico5038
3,080 Expert 2GB
The comboboxes can be used to select the project(s) and I advise you to read the "cascading comboboxes" article (http://bytes.com/topic/access/insigh...mbo-list-boxes)

The only problem left is assigning a new project for a Localité / type combination.
I would use a separate [New] button to trigger such an event.
There you can find the MAX([Nurméro du projet]) WHERE Localité and Type are from the comboboxes. When no record is returned start with 1 otherwise add 1 to the found MAX.

Getting the idea ?

Nic;o)

PS: It's better to use no spaces in table and fieldnames. I would use NurméroDuProjet,thus making the brackets "[" and "]" obsolete in queries...
Apr 3 '15 #5
here is a sample db

if it helps

thanks
Attached Files
File Type: zip sample.zip (58.1 KB, 57 views)
Apr 7 '15 #6
nico5038
3,080 Expert 2GB
Hi vartaxe,

I've posted in the past a sample that might come in handy:
http://bytes.com/attachments/attachm...tbeforenew.zip

First I would recommend to use this Object/Action principle as it's the same way as Access works with tables/queries/etc. You get to see all of them and (by the right-click) you can activate the action you want (Edit/Delete/etc.).

By making a selection form with a subform with all Projets, the user will easily navigate to the needed projet.
Next the buttons on the right show the actions like [New], [Update] [Print], etc.

Finally this sample shows the way I add a new record. This is by inserting it on forehand (the position where you can determine the sequencenumber of the new projet) and when the user cancels the operation, by deleting the inserted record.

Just press the [New] button and see the two combo's [CodePrefix] and [RecType]. After selecting them you get a code like you need for your projet. Here however the [CodePrefix] determines the number and in your case both combo's are needed.
So for determing the sequence number you can use a count of the number of localité and type and add +1. (think of the NULL when it's a new combination, use the NZ() function!)

In this sample datadase the +1 is handled in the module "modEPMroutines"

Lot's of info in this sample, but hope you're able to extract some usefull guidelines for your database from.

Getting the idea ?

Nic;o)
Apr 7 '15 #7
can't get it to work

Expand|Select|Wrap|Line Numbers
  1. Private Sub Numéro_du_projet_Click()
  2. If Len(Me.Numéro_du_projet & "") < 1 Then
  3. ElseIf Me.Localité.Column(2) = "" Or Me.Type.Column(2) = "" Then
  4. MsgBox "Veuillez renseigner la localité et le type de projet."
  5. Else
  6. tSeq = Nz(DMax("Séquence", "Projets", "Localité=" & Me.Localité & " and " & "Type=" & Me.Type))
  7. hiCount = Nz(DLookup("Compteur", "Projets", "Séquence=" & tSeq), 0) + 1
  8. Me.Numéro_du_projet = Me.Localité.Column(2) & "-" & Me.Type.Column(2) & "-" & Format(Compteur, "000")
  9. End If
  10. End Sub
  11.  
Apr 8 '15 #8
it is making me go nuts

Expand|Select|Wrap|Line Numbers
  1. Private Sub Numéro_du_projet_Click()
  2. If Len(Me.Numéro_du_projet & "") < 1 Then
  3.      If Me.Localité.Column(2) = "" Or Me.Type.Column(2) = "" Then
  4.           MsgBox "Veuillez renseigner la localité et le type de projet."
  5.           Exit Sub
  6.      End If
  7.      tSeq = Nz(DMax("Séquence", "Projets", "Localité='" & Me.Localité.Column(2) & "' and " & "[Type]='" & Me.Type.Column(2) & "'"), 0)
  8.      hiCount = Nz(DLookup("Compteur", "Projets", "Compteur=" & tSeq & ""), 0) + 1
  9.      Me.Numéro_du_projet = Me.Localité.Column(2) & "-" & Me.Type.Column(2) & "-" & Format(hiCount, "000")
  10. End If
  11. End Sub
  12.  
Apr 10 '15 #9
jforbes
1,107 Expert 1GB
So Vartaxe, what is making you nuts?

What do you want to happen and what is actually happening?
Apr 10 '15 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: jaad | last post by:
Hello, I have a database that was written in access 2007 on my pc. I wanted to work off site with the database so I uploaded it onto my laptop which is loaded with access 2010 beta. When I...
2
by: sierra7 | last post by:
It seems Access 2010 is associating an 'input mask' or field type with a combo box when a form is opened, even though there is no Format setting on the control. I have a form which has been...
1
by: Alan Yim | last post by:
Hi folks, My company recently upgraded our Office suite from 2003 to 2010. The problem in particular is with an Access database that was originally designed in Access 2003. The code in question...
5
by: neelsfer | last post by:
I got a new work laptop last week with Access 2010 pre-loaded.I also installed the new Office 2010 service pack 1. I then loaded 2 of my regularly used Access 2007 + service pack 2 applications on...
4
by: jbrumbau | last post by:
Hello, In Access 2010/2007, how do you prevent users from flipping into design view from the ribbon? I do not want to hide the entire ribbon (DoCmd.ShowToolbar "Ribbon", acToolbarNo) or even the...
4
beacon
by: beacon | last post by:
Hi everybody, My title may not exactly describe my issue, so please forgive my lack of creativity today. I've got a database that was created in Access 2003 that I've opened in Access 2010. I...
1
by: Sweeda | last post by:
Hi guys, as you read in the title, I've got problems with more than one record in a table: On opening the form that displays the field it appears the error 3197 "The Microsoft Jet database...
1
topher23
by: topher23 | last post by:
A layout provides a grouping method for controls on a form or report. The two default layout types are Tabular (labels in form header, controls in detail), and Stacked (labels to the left, controls...
2
by: irslan rafique | last post by:
Hi, I am creating a database using Access 2010 Web Database. I have two tables: 1-Maintbl with these fields: 1- Date 2- RTNo 3-DriverName 4- ConID 5-ConName 6- Zone 7-...
2
by: CLSkcab | last post by:
Background: Front End: MS Access 2010/VBA, Back End: MS SQL Server 2008 Can an Access 2010 program start another Access 2010 program and pass data to the one it starts? Thanks in advance.
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.