I have two forms, frma and frmb, both are for inputting new records and are
based on a table, tblmonth, both have two controls, txtmonth and
txtmonthlabela which are based on the fields in the table.
frma has a command button that opens frmb. I want the command buuton to pass
the value of txtmonth and txtmonthlabela from frma to the controls on frmb
I am using this code on the command button on frma:
Private Sub cmdOpenform_Click()
On Error GoTo Err_cmdOpenform_Click
DoCmd.OpenForm "frmb", , , , acFormEdit, , Me.txtMonth
DoCmd.Close acForm, Me.Name
Exit_cmdOpenform_Click:
Exit Sub
Err_cmdOpenform_Click:
MsgBox Err.Description
Resume Exit_cmdOpenform_Click
End Sub
and this code on the onload event of frmb:
Private Sub Form_Load()
If Len(Me.OpenArgs & "") > 0 Then
Me.txtMonth = Me.OpenArgs
Me.txtMonth.SetFocus
End If
End Sub
The code at the moment only passes the value of txtmonth and I want to pass
the value of txtmonthlabela as well. Also because txtmonth has the no
duplicates property set on the field I get an error message to say I can't
create the new record because it already exists.
Can anyone help?
TIA
Tony Williams 5 9190
Pass a string as your argument that contains the month data + a percent sign
(or something that would never be part of an actual value) + month label
data. Then, in your OnLoad code, parse out the two separate Strings:
Dim i As Integer
Dim s As String
s = CStr(Me.OpenArgs)
i = InStr(1, s, "%")
Me.txtmonth = Left$(s, i - 1)
Me.txtmonthlabela = Mid$(s, i + 1)
Darryl Kerkeslager
Darryl I'm a newbie so that went a bit over my head.
Does this code go in the onclick expression or in the onload? How do I get
pick up both values from the first form? In other words how does your code
relate to the code I posted? Any ideas on my second part of my question?
Thanks for your help
Tony
"Darryl Kerkeslager" <Ke*********@comcast.net> wrote in message
news:Bv********************@comcast.com... Pass a string as your argument that contains the month data + a percent
sign (or something that would never be part of an actual value) + month label data. Then, in your OnLoad code, parse out the two separate Strings:
Dim i As Integer Dim s As String s = CStr(Me.OpenArgs) i = InStr(1, s, "%") Me.txtmonth = Left$(s, i - 1) Me.txtmonthlabela = Mid$(s, i + 1)
Darryl Kerkeslager
Hi Tony,
Darryl's code goes into the Form_Load event. I have made an example for your
code, see below. The code in the cmdOpenForm_Click procedure assumes that
both values are actually entered and that these do not contain the %
character (as Darryl already suggested).
HJ
frma: cmdOpenForm_Click
Private Sub cmdOpenForm_Click()
On Error GoTo Err_cmdOpenform_Click
Dim strArgs As String
strArgs = Me.txtMonth & "%" & Me.txtMonthLabelA
DoCmd.OpenForm "frmb", , , , acFormEdit, , strArgs
DoCmd.Close acForm, Me.Name
Exit_cmdOpenform_Click:
Exit Sub
Err_cmdOpenform_Click:
MsgBox Err.Description
Resume Exit_cmdOpenform_Click
End Sub
frmb: Form_Load
Private Sub Form_Load()
If Len(Me.OpenArgs & "") > 0 Then
Dim i As Integer
Dim s As String
s = CStr(Me.OpenArgs)
i = InStr(1, s, "%")
Me.txtMonth = Left$(s, i - 1)
Me.txtMonthLabelA = Mid$(s, i + 1)
Me.txtMonth.SetFocus
End If
End Sub
Thanks HJ, that's a great help for me
Tony
"HJ" <hj********@spamhotmail.com> wrote in message
news:41***********************@news.xs4all.nl... Hi Tony,
Darryl's code goes into the Form_Load event. I have made an example for
your code, see below. The code in the cmdOpenForm_Click procedure assumes that both values are actually entered and that these do not contain the % character (as Darryl already suggested).
HJ
frma: cmdOpenForm_Click
Private Sub cmdOpenForm_Click() On Error GoTo Err_cmdOpenform_Click
Dim strArgs As String strArgs = Me.txtMonth & "%" & Me.txtMonthLabelA
DoCmd.OpenForm "frmb", , , , acFormEdit, , strArgs DoCmd.Close acForm, Me.Name
Exit_cmdOpenform_Click: Exit Sub
Err_cmdOpenform_Click: MsgBox Err.Description Resume Exit_cmdOpenform_Click
End Sub
frmb: Form_Load
Private Sub Form_Load()
If Len(Me.OpenArgs & "") > 0 Then Dim i As Integer Dim s As String s = CStr(Me.OpenArgs) i = InStr(1, s, "%") Me.txtMonth = Left$(s, i - 1) Me.txtMonthLabelA = Mid$(s, i + 1) Me.txtMonth.SetFocus End If
End Sub
1. In frma, declare a string variable srtDateMonth, and pass it with the
following value = Me.txtmonth.Value & "," & Me.txtmonthlabela.Value. In
frmb, parse the srtDateMonth value into the two values using the InStr and
Mid functions.
2. In the table, set allow duplicates "yes" for the txtmonth field and
create a joint Primary Key on txtmonth and the existing primary key.
--
Tony D'Ambra
Web Site: aadconsulting.com
Web Blog: accessextra.net
"Tony Williams" <tw@tcpinvalid.com> wrote in message
news:cp**********@titan.btinternet.com... I have two forms, frma and frmb, both are for inputting new records and are based on a table, tblmonth, both have two controls, txtmonth and txtmonthlabela which are based on the fields in the table. frma has a command button that opens frmb. I want the command buuton to pass the value of txtmonth and txtmonthlabela from frma to the controls on frmb I am using this code on the command button on frma: Private Sub cmdOpenform_Click()
DoCmd.OpenForm "frmb", , , , acFormEdit, , Me.txtMonth DoCmd.Close acForm, Me.Name Exit_cmdOpenform_Click: Exit Sub
Err_cmdOpenform_Click: MsgBox Err.Description Resume Exit_cmdOpenform_Click End Sub
and this code on the onload event of frmb: Private Sub Form_Load() If Len(Me.OpenArgs & "") > 0 Then Me.txtMonth = Me.OpenArgs Me.txtMonth.SetFocus End If
End Sub
The code at the moment only passes the value of txtmonth and I want to pass the value of txtmonthlabela as well. Also because txtmonth has the no duplicates property set on the field I get an error message to say I can't create the new record because it already exists. Can anyone help? TIA Tony Williams
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Shyguy |
last post by:
I have two forms that both open the same (3rd) form.
The third form does the same thing, but a little differently depending
on which form it is opened from. Is there a way I can check which
form...
|
by: Tony Williams |
last post by:
I have two forms, frma and frmb, both are for inputting new records and are
based on a table, tblmonth, both have two controls, txtmonth and
txtmonthlabela which are based on the fields in the...
|
by: beowulfs |
last post by:
Here's what I've got:
I've got a form with combo boxes. you can select already existing
company names or type in new ones. if you type in a new one, it
prompts you to double click the combo...
|
by: fredindy |
last post by:
I'm having trouble figuring out what I need to do here. Basically, I
want to pull data from several different tables and send them to a form
using open args. However, the form that is being fed...
|
by: Del |
last post by:
I have a form call frmMMD-PCKR. This form has seven buttons, each
button represents a part. When I click on any of the buttons they open
another form called frmTallyTagMMDPCKR.
On the...
|
by: Dave |
last post by:
Access 2002...I need to open a popup at the location of a mouse
dblclick. Can anyone help with this? I can get the mouse X & Y, but
I'm not sure how to open a form in a specific location by code....
|
by: vanlanjl |
last post by:
Okay lets see if I can do this with out confusing myself or others. First I will give ALL the details then state my problem and request at the bottom.
Tables:
tblContacts
ID
Company
LastName...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
| |