473,473 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

OpenArgs and New Records, within the same form

94 New Member
Is there any way to create a new record (using the following code or similair)

Expand|Select|Wrap|Line Numbers
  1. DoCmd.GoToRecord , , acNewRec
But have it carry through certain values from the previous form you have created?

The reson being, I want to be able to create a lot of site records at once, all with the same customer, and same project name. Obviously, getting the customer and project name, etc from the main project setup screen is no problem as you just use openArgs, but I cant see a way of doing it once in the form, and obviusly when you click new, it loses all the openargs.

Any ideas anyone?
Jan 25 '11 #1
5 2890
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
I will admit, that I haven't actually tested it, but I don't THINK that the form looses the OpenArgs when you create a new record. So you should be able to just add code beneath the line you allready have:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.GoToRecord , , acNewRec 
  2. If Me.OpenArgs & ""<>"" then
  3.   'Assuming you have only passed 1 value, the project ID
  4.   Me.tb_ProjectID=clng(Me.OpenArgs)
  5. End If
  6.  
Jan 25 '11 #2
James Bowyer
94 New Member
Presumably if I were to want more than one openargs, I could split it using:
Expand|Select|Wrap|Line Numbers
  1. Dim StrOpenArgs as string
  2. StrOpenargs = Split(Me.Openargs, ";")
  3. Me.tb_ProjectID=clng(StrOpenArgs(0))
  4.  
and so on... Or would that not work?
Jan 25 '11 #3
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
If you get the syntax correct :P
Expand|Select|Wrap|Line Numbers
  1. Dim StrOpenArgs() as string 
Notice the added (), to indicate its an array.

What I personally use/prefer is to encode my strings in an xml like format.
Lets presume I want to pass on information to a form, saying its type and ID.
I would do like This:
Expand|Select|Wrap|Line Numbers
  1. dim strArgs as string
  2. strArgs="<Type>" & me.Tb_Type & "</Type><ID> & me.Tb_ID & "</ID>"
  3. docmd.OpenForm "frm_Example",,,,,,strArgs

Then I have code in a module:
Expand|Select|Wrap|Line Numbers
  1. Public Function getXML(strXML As String, strElement As String) As String
  2. On Error GoTo ErrHandler
  3.     If InStr(1, strXML, "<" & strElement & ">", vbTextCompare) > 0 And InStr(1, strXML, "</" & strElement & ">", vbTextCompare) > 0 Then
  4.         'Found it
  5.         Dim intLeft As Integer
  6.         Dim intRight As Integer
  7.         intLeft = InStr(1, strXML, "<" & strElement & ">", vbTextCompare) + Len(strElement) + 2
  8.         intRight = InStr(1, strXML, "</" & strElement & ">", vbTextCompare)
  9.         getXML = Mid(strXML, intLeft, intRight - intLeft)
  10.         Else
  11.  
  12.         GoTo badXML
  13.     End If
  14.  
  15. Exit Function
  16.  
  17. badXML:
  18.     MsgBox "An error occured while trying to retrieve XML information,probably due to bad tags" & vbNewLine & "Please contact TheSmileyOne"
  19.     Exit Function
  20.  
  21. ErrHandler:
  22.     MsgBox "An error occured while trying to retrieve XML information" & vbNewLine & "Please contact TheSmileyOne" & vbNewLine & "Error Number:" & Err.Number & vbNewLine & "Error Description:" & Err.Description, vbOKOnly + vbCritical
  23.     Err.Clear
  24.     Exit Function
  25. End Function
So in the form you opened you could get the information from the OpenArgs like this:
Expand|Select|Wrap|Line Numbers
  1. Dim strType as string
  2. dim lngID as long
  3. strType=getxml(me.OpenArgs,"Type")
  4. lngID=clng(getxml(me.openargs,"ID"))
Why do I do it this way? Well if you only have 1 or 2 arguments to pass in the openArgs its not that complicated, but sometimes I might have 4 or 5, and then I simply find it easier to debug, when viewing a Openargs string that also indicates what each value represents.
Jan 25 '11 #4
James Bowyer
94 New Member
Doh! I always forget The () on the end until I get an error...

I didn't realise OpenArgs stays in the memory, so its a lot easier than I originally thought.

Ta very much!!
Jan 25 '11 #5
NeoPa
32,556 Recognized Expert Moderator MVP
James, an important point to remember when perpetuating data across multiple records, or even just perpetuating any data into a new record, is to use the .DefaultValue property, rather than the .Value property. They can both be made to work, it's true, but you get far fewer problems and issues when done using the .DefaultValue property.

PS. Smiley, I like your thinking about the XML thing. I tend to use Split()/Join() array structures myself, but I might look into the XML thing a little more deeply now you've posted this.
Jan 25 '11 #6

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

Similar topics

3
by: Craig Brown | last post by:
I would like to open selected (Filtered) records in a form. I currnetly have a custom menu but would like to only open certain records from i.e Button 1 will open Site 1 Button 2 will open...
4
by: jean.ockert | last post by:
Greetings. Access version 2003 on an XP system I am using the template "Event Management" database as the primary database and need additional functionality added. I have a dance studio. ...
3
by: Bob Sanderson | last post by:
I am trying to create a form for a MySQL database similar to a spreadsheet. The idea is to display a list of records, with the last line of the list being an input form. When the user enters data...
1
by: NumberCruncher | last post by:
Hi All, I am struggling with setting up my first system of tables, forms,and reports, and could use your help! I am setting up a database to keep track of the production of a produced item. The...
11
by: TheDataGuy | last post by:
Using MS ACCESS 2002 I developed a FORM, and within that FORM, I created and added a SEARCH BUTTON, and then I created a SUB-FORM, so that when an the END USER clicks on the FORM it will POP-UP...
7
by: dbnut | last post by:
• I am using Access Trial 2007 in 2003 Mode. • I designed a Form to track what tickets still need to be issued using a split form: ________________________________________ Ticket 14 ...
5
by: BD | last post by:
I am coding with C# in Visual Studio 2005 for a database application residing on remote MS SQL Server 2005. What I want to do is open the same form but from 2 different places and only one...
1
by: Birky | last post by:
I am truly stuck and need some help on how to put this form together; any help or suggestions you can provide would be greatly appreciated. (Sorry this one is so long but I believe it is necessary to...
6
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate...
2
by: nomvula | last post by:
hi guys i need some help to duplicate records on my form datasheet: here's the example of my form results: ClientLookup DateCaptured ForecastDate Description ForecastQuantity Forecast Actual UJ...
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
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.