473,396 Members | 1,693 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.

Using Existing File Number to Copy Data

tdw
206 100+
Hi, I have taken over an orders database that someone else created. I have basically backwards engineered it, thereby learning Access and VBA on my own. I have successfully made many improvements to it, but I am stuck on two things.
First thing is, I want to be warned if I have just typed a value into the "address" line of the form that is a duplicate of an already existing value in the "address" column on a different table, but i don't want it to prevent me from entering that duplicate if I want to... just warn me. I have tried several things, but the one thing I can't seem to get around is that if the address is new, i.e. is not already duplicated in the other table, I still get a query result of a blank form. what I want is for it to do nothing at all if the address I just typed is new. The second thing is I want to create a form that lets me type our file number associated with an order, and upon 'lose focus' automatically fill in several other values in the form, and then have that info saved into it's own table. the reason for this is so that I have a dedicated table for orders that are being assigned to a crew to be taken care of today, without needing to re-type all the data.
I have tried several of the solutions to similiar problems posted on here and so far no luck. It either leaves all the fields blank, or gives me a parameters error.
Mar 29 '07 #1
12 2196
Rabbit
12,516 Expert Mod 8TB
Can you post the code you're using? It'll give us something to work off of.
Mar 30 '07 #2
MMcCarthy
14,534 Expert Mod 8TB
Hi, I have taken over an orders database that someone else created. I have basically backwards engineered it, thereby learning Access and VBA on my own. I have successfully made many improvements to it, but I am stuck on two things.
First thing is, I want to be warned if I have just typed a value into the "address" line of the form that is a duplicate of an already existing value in the "address" column on a different table, but i don't want it to prevent me from entering that duplicate if I want to... just warn me. I have tried several things, but the one thing I can't seem to get around is that if the address is new, i.e. is not already duplicated in the other table, I still get a query result of a blank form. what I want is for it to do nothing at all if the address I just typed is new.
Create an after update event on the [address] textbox as follows:
Expand|Select|Wrap|Line Numbers
  1. Private Sub address_AfterUpdate()
  2.    If Not IsNull(DLookup("*", "OtherTableName", "[address]='" & Me![address] & "'") Then
  3.       Msgbox "Address already in table ...etc.", vbOkOnly
  4.    End If
  5. End Sub
  6.  
The second thing is I want to create a form that lets me type our file number associated with an order, and upon 'lose focus' automatically fill in several other values in the form, and then have that info saved into it's own table. the reason for this is so that I have a dedicated table for orders that are being assigned to a crew to be taken care of today, without needing to re-type all the data.
I have tried several of the solutions to similiar problems posted on here and so far no luck. It either leaves all the fields blank, or gives me a parameters error.
I will need a clearer explanation of what you are trying to do here and what table(s) the current form is based on and what table you wish the data saved to. As the previous example this can be programmed in a triggered event but I will need to know more about what's going on to figure out when and how to trigger it.

Mary
Mar 30 '07 #3
tdw
206 100+
Here is the Code for the form for creating new orders. I tried the code suggested previously, and also tried it as a Lost Focus event, as you can see here. It doesn't respond. For the heck of it I threw in an 'Else' to see if it even gives me that message box. Nothing, no response. This Add New Order form is linked/associated (not sure the right term) with a table called SC_NEW. Once an order is typed up, there is a button to click that enters it into an open orders table called SC_OPEN. Then, after we have completed and billed the job we click a button to archive it (close the order) in the table SC_ARCH. The original programmer only had the SC_OPEN and SC_ARCH tables. The problem with that was that if we closed an order (i.e. due to cancellation) but then wanted to re-open it (i.e. customer changed their mind and said go ahead with it) we couldn't move the record back into the Open Orders table because of the autonumber field that was being used to generate our file numbers (through a complex and, to me kind of bizarre, series of queries and formulas). An example of a file number: 2007-0987 (where the year ordered is 2007 and it's the 987th order for the year). So I added the SC_NEW table, which now has the autonumber field to generate the file number, then on button click moves the date to the SC_OPEN table which does not have autonumber field. Now we can move a record back into it from the SC_ARCH table with no problem. Now I want to add a feature that warns when we are about to type in an order with the same property address that we already have an open order for, because sometimes our clients fax us the same request twice and we don't catch it. Then we end up with two orders for the same job and that can get messy. But I don't want it to prevent me from reusing an address, in case we are entering a seperate order for a different job at the same address. So in a New Order form, linked to the SC_NEW table, I need the address field to recognize a duplicate address that is located in the SC_OPEN table. Since my original post had two questions, I will go into more detail on the other question in a seperate reply, so that they can be getting answered seperately. Thanks so much!

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. '   Path Name code Variable Definitions
  4.     Private stFileNumber As String
  5.     Private stFileName As String
  6.     Private stPathName As String
  7.     Private stPFName As String
  8. Private cusnamers As Recordset
  9. Private dbs As Database
  10.  
  11. Private Sub ADDRESS_LostFocus()
  12.  
  13. DoCmd.SetWarnings True
  14.     If Not IsNull(DLookup("*", "SC_OPEN", "[ADDRESS]='" & Me.ADDRESS & "'")) Then
  15.         MsgBox "There is already an Open Order with this Address", vbOKOnly
  16.     Else: MsgBox "this isn't working"
  17.     End If
  18.  
  19. End Sub
  20.  
  21. Private Sub Create_Order_File_Structure_Click()
  22. On Error GoTo Err_Create_Order_File_Structure_Click
  23.  
  24. '   Yes No Box
  25.     Dim Msg, Style, Title, Response
  26.     Msg = "Are you sure you want to Create this new Open Order?"    ' Define message.
  27.     Style = vbYesNo   ' Define buttons.
  28.     Title = "Create Order"    ' Define title.
  29.     Response = MsgBox(Msg, Style, Title)
  30. If Response = vbYes Then    ' User chose Yes
  31.  
  32.     RunCommand acCmdSaveRecord
  33.  
  34.     If Me![REC_ID] <> 0 And Me![FILE_NO] = "" Then
  35.     DoCmd.SetWarnings False
  36.         If Me![REC_ID] - 10493 < 10 Then ' Numeric Value 10493 is last value of rec_id upon year change for file_id renum
  37.         DoCmd.OpenQuery "FILE_NO_Update_New_000", acNormal, acEdit
  38.         GoTo Confirm_File_No_Creation
  39.         End If
  40.  
  41.         If Me![REC_ID] - 10493 < 100 Then
  42.         DoCmd.OpenQuery "FILE_NO_Update_New_00", acNormal, acEdit
  43.         GoTo Confirm_File_No_Creation
  44.         End If
  45.  
  46.         If Me![REC_ID] - 10493 < 1000 Then
  47.         DoCmd.OpenQuery "FILE_NO_Update_New_0", acNormal, acEdit
  48.         GoTo Confirm_File_No_Creation
  49.         End If
  50.  
  51.     DoCmd.OpenQuery "FILE_NO_Update_New", acNormal, acEdit
  52.  
  53. Confirm_File_No_Creation:
  54.     DoCmd.SetWarnings True
  55.     MsgBox ("The File Number Has Been Created For The Order")
  56.  
  57.     End If
  58.  
  59.     stFileNumber = [FILE_NO]
  60.     stPathName = "O:\" & [FILE_NO]
  61.     stFileName = [FILE_NO] & ".rtf"
  62.     stPFName = stPathName & "\" & stFileName
  63.  
  64.     If Dir$(stPathName, vbDirectory) <> "" Then  ' Does Path Already Exist?
  65.         MsgBox ("The directory " & stPathName & " Already exits")
  66.         GoTo Exit_Create_Order_File_Structure_Click
  67.     Else
  68.         MkDir Path:=(stPathName)   '  Create Directory Structure
  69.     End If
  70.  
  71.     Application.FileSearch.RefreshScopes  '  Refresh Directory Structure
  72. '   Create Report File
  73.     DoCmd.OutputTo acOutputReport, "File Creation", acFormatRTF, stPFName
  74.     MsgBox ("The " & stPathName & " folder and the file " & stFileName & " have been created")
  75.  
  76. Else    ' User chose No.
  77.     GoTo Exit_Create_Order_File_Structure_Click
  78. End If
  79.  
  80. '   Query Name variable definitions
  81.     Dim stQName As String
  82.     Dim stQName1 As String
  83.     stQName = "APPEND NEW RECORD TO OPEN" 'Named Database Query
  84.     stQName1 = "Delete From New"  'Named Database Query
  85.  
  86.     DoCmd.SetWarnings False
  87.     DoCmd.OpenQuery stQName, acNormal, acEdit   'Run Query
  88.     DoCmd.SetWarnings True
  89.  
  90. '   Yes No Box
  91.     Msg = "Do you want to Print " & stFileNumber & "?"    ' Define message.
  92.     Style = vbYesNo   ' Define buttons.
  93.     Title = "Print New Order"    ' Define title.
  94.     Response = MsgBox(Msg, Style, Title)
  95. If Response = vbYes Then    ' User chose Yes
  96.     DoCmd.RunMacro ("Print New Order") '   Print New Order
  97. End If
  98.  
  99.     DoCmd.SetWarnings False
  100.     DoCmd.OpenQuery stQName1, acNormal, acEdit  'Run Query
  101.     DoCmd.Requery   'Refresh Form
  102.     DoCmd.SetWarnings True
  103. Exit_Create_Order_File_Structure_Click:
  104.     Exit Sub
  105.  
  106. Err_Create_Order_File_Structure_Click:
  107.     MsgBox Err.Description
  108.     Resume Exit_Create_Order_File_Structure_Click
  109. End Sub
  110.  
  111. Private Sub Form_Load()
  112. DoCmd.SetWarnings False
  113. DoCmd.OpenQuery "customer_distinct_create_table", acNormal, acEdit
  114. DoCmd.SetWarnings True
  115.  
  116. Set dbs = CurrentDb()
  117. Set cusnamers = dbs.OpenRecordset("cust", dbOpenTable)
  118.  
  119. DoCmd.SetWarnings False
  120. DoCmd.OpenQuery "subdivision_distinct_create_table", acNormal, acEdit
  121. DoCmd.SetWarnings True
  122.  
  123. End Sub
  124.  
  125. Private Sub ORDER_KeyUp(KeyCode As Integer, Shift As Integer)
  126.  
  127.  
  128. Dim nl As Integer 'number of characters typed in order field
  129. Dim i As Integer
  130. nl = Len(ORDER.Text)
  131. If nl >= 5 Then
  132.         cusnamers.MoveFirst
  133.         For i = 1 To cusnamers.RecordCount
  134.         If UCase(Left(cusnamers("cusname"), nl)) = UCase(ORDER.Text) Then
  135.             ORDER.Text = cusnamers("cusname")
  136.             Exit For
  137.         Else
  138.             cusnamers.MoveNext
  139.         End If
  140.         Next
  141.  End If
  142. End Sub
  143.  
Mar 30 '07 #4
tdw
206 100+
Ok, my other issue. When we send a job out to the field, currently the field coordinator has to hand write the file number, address, etc. down. The reason is that if we get a phone call about the status of an order, and if we can't find the folder for the order in our office, we need to know if it's lost, never been created, or out in field being worked on right now. so the field coordinator writes down all the jobs every morning and what crew he sent them out with. I am trying to give him a way to get on our orders database, type into a form what crew it's going with, type in the file number of the job, and have it fill in the rest of the info, like the address, subdivision, lot number, etc. This would expedite the process of getting the crews out in the field in the morning. Then I want that data stored so that we can look up what job went out with whom on any given day. So I need the form to lookup info from the SC_OPEN table based on the file number he enters into the form, then store it all on a separate table that I would call IN_FIELD or some such thing. Then I can create a query to look up all jobs that went in the field on a certain day and get a report of them and what crew they went with. One reason I think I should do all this with it's own table rather than adding fields to the SC_OPEN table is that we would want to be able to enter criteria for a particular date, and not have it need to search across two tables for the data (some jobs that went in the field may not be closed yet, or some may be, so some would be in SC_OPEN and some in SC_ARCH). Also that would allow him to accidentally screw up data on his In Field report without screwing up our data in the SC_OPEN or SC_ARCH tables.
Mar 30 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
Open the form in design view. Go to textbox [address] and open properties window. Under the event tab make sure [Event Procedure] appears against the Lost Focus or After Update event as appropriate. I would leave it as After Update BTW.
Mar 30 '07 #6
tdw
206 100+
Open the form in design view. Go to textbox [address] and open properties window. Under the event tab make sure [Event Procedure] appears against the Lost Focus or After Update event as appropriate. I would leave it as After Update BTW.

Yeah, makes sense to have it as After Update. It's just that I tried that and when it didn't work I thought I'd try it on Lost Focus. Ok, I've moved to back to After Update, but still nothing. It does say [Event Procedure] and it does go to the right code when I click the "..." button that appears. When exactly shoud the message box appear? I tried tabbing out of the address box after typing, nothing happened, so I clicked to the the next record and got no response along the way. I know that I am typing an existing address. By the way, if it makes any difference, I am using Access 2003, and I believe that the database was created using 2002.
Mar 30 '07 #7
MMcCarthy
14,534 Expert Mod 8TB
Yeah, makes sense to have it as After Update. It's just that I tried that and when it didn't work I thought I'd try it on Lost Focus. Ok, I've moved to back to After Update, but still nothing. It does say [Event Procedure] and it does go to the right code when I click the "..." button that appears. When exactly shoud the message box appear? I tried tabbing out of the address box after typing, nothing happened, so I clicked to the the next record and got no response along the way. I know that I am typing an existing address. By the way, if it makes any difference, I am using Access 2003, and I believe that the database was created using 2002.
As a test try compiling the code in 2003 and see if any errors appear.
Mar 30 '07 #8
MMcCarthy
14,534 Expert Mod 8TB
Try this code ...

Expand|Select|Wrap|Line Numbers
  1. Private Sub ADDRESS_AfterUpdate()
  2.  
  3.    If DLookup("*", "SC_OPEN", "[ADDRESS]='" & Me!ADDRESS & "'") <> 0 Then
  4.       MsgBox "There is already an Open Order with this Address", vbOKOnly
  5.    Else
  6.       MsgBox "this isn't working"
  7.    End If
  8.  
  9. End Sub
Mar 30 '07 #9
tdw
206 100+
Try this code ...

Expand|Select|Wrap|Line Numbers
  1. Private Sub ADDRESS_AfterUpdate()
  2.  
  3.    If DLookup("*", "SC_OPEN", "[ADDRESS]='" & Me!ADDRESS & "'") <> 0 Then
  4.       MsgBox "There is already an Open Order with this Address", vbOKOnly
  5.    Else
  6.       MsgBox "this isn't working"
  7.    End If
  8.  
  9. End Sub
Ok, tried it. Still nothing, no message box. When you say to try compiling the code, do you mean the 'compile orders' in the 'debug' menu? If so, it found no errors in the code for this form, just in the code for the other form I'm trying to create that's unrelated to this one.

I was just reading up on using 'dlookup' and might have found what I need for my other question, but no insight into this one
Mar 30 '07 #10
MMcCarthy
14,534 Expert Mod 8TB
Sorry my fault, try this ...

Expand|Select|Wrap|Line Numbers
  1. Private Sub ADDRESS_AfterUpdate()
  2.  
  3.    If DCount("*", "SC_OPEN", "[ADDRESS]='" & Me!ADDRESS & "'") <> 0 Then
  4.       MsgBox "There is already an Open Order with this Address", vbOKOnly
  5.    Else
  6.       MsgBox "this isn't working"
  7.    End If
  8.  
  9. End Sub
Mary
Mar 30 '07 #11
tdw
206 100+
YES!! It worked. Thank you so much! Now I will add a yes/no message asking the user if they would like to view the existing order with that address, program it to do so, and I'm all set! That part should be easy.

I will try a couple things on the other question I had, and I'll start a new thread restating that question if I still have no luck.


Sorry my fault, try this ...

Expand|Select|Wrap|Line Numbers
  1. Private Sub ADDRESS_AfterUpdate()
  2.  
  3.    If DCount("*", "SC_OPEN", "[ADDRESS]='" & Me!ADDRESS & "'") <> 0 Then
  4.       MsgBox "There is already an Open Order with this Address", vbOKOnly
  5.    Else
  6.       MsgBox "this isn't working"
  7.    End If
  8.  
  9. End Sub
Mary
Mar 30 '07 #12
MMcCarthy
14,534 Expert Mod 8TB
YES!! It worked. Thank you so much! Now I will add a yes/no message asking the user if they would like to view the existing order with that address, program it to do so, and I'm all set! That part should be easy.

I will try a couple things on the other question I had, and I'll start a new thread restating that question if I still have no luck.
You're welcome.
Mar 30 '07 #13

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

Similar topics

3
by: Mahesha | last post by:
Hello, I'm new to C++ and I have requirement to open a existing text file in write mode and write 2 new lines of text in the beginning of the file. I'm working with fstream standard library. If...
1
by: kyma via .NET 247 | last post by:
Hi, I haveto use VB to create a form that reads an exisiting XML fileand then allows updates via the VB form. My problem is that I was able to get VB to read a simple XML file(people.XML), but...
3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
47
by: Bonj | last post by:
I downloaded the gzlib library from zlib in order to do compression. (http://www.gzip.org/zlib) The prototype of the compression function seems to be int compress (Bytef *dest, uLongf *destLen,...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
53
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.