 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 29th, 2006, 01:47 PM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Using command buttons in Access
I am trying to use a command button to execute a query for each line item that is returned in a continuous form. The query associated with the command button references a field in a line in the continuous form. The problem I am running into is that the code references the first record returned no matter what line of the continuous form I am trying to query off of.
Example, if there are 15 line items returning values for this field. When I push the button associated with items 2-15 it returns the value seen in field 1 everytime.
Am I trying to do the impossible, or is there a way to accomplish this task?
Thank you,
KellJW
|
|

June 30th, 2006, 07:20 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
I do the same thing and this is the code I use:
'-----
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmDetails"
stLinkCriteria = "[DetailsID]=" & Me![DetailsID]
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
'-----
This works fine (for a number field). What code are you using?
mmcdonal
|
|

June 30th, 2006, 07:21 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
I should mention that in the continuous form, in your case, there would be 15 buttons, one on each record.
mmcdonal
|
|

July 3rd, 2006, 02:02 PM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Right now the only code associated with these buttons is a simple message box to display the value in the field. I have run into this problem before and worked around it, but never really got to the bottom of the issue. In this case, the 15 buttons are what I want and need so i will give this a shot and hope I do it right.
Thanks.
|
|

July 3rd, 2006, 02:21 PM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Here is the code I have for the button. The button is called 'DataEntry'.
If IsNull(Me.DataID) Or Me.DataID = "" Then
DoCmd.OpenForm "RGAData", acNormal
Forms![RGAData]![RGANum] = Me.RGANum
Forms![RGAData]![CAT] = Me.CatNum
Forms![RGAData]![FrSer#] = Me.DateCode
Forms![RGAData]![Comm] = Me.EvalDesc
ElseIf Len(Me.DataID) > 1 Then
MsgBox Me.DataID
MsgBox Me.LineNum
'DoCmd.OpenForm "RGAData2", acNormal
End If
As you can see I am trying to populate a form based off of the 'DataID' number which is automatically generated each time a new record is written to the table. "RGAData" and "RGAData2" are physically the same form, the only difference is that RGAData2 is populated from pre-existing data in a table.
I don't know if I am just having difficulty following what you are doing in your code, I am a rookie, or if maybe I didn't explain well enough. I hope the snippit of code above clarifies.
KellJW
|
|

July 5th, 2006, 06:11 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
I would grab the parameters first in a variable, and then pass the variable to the form before it is opened. I don't think this code is doing the trick:
DoCmd.OpenForm "RGAData", acNormal
Forms![RGAData]![RGANum] = Me.RGANum
Forms![RGAData]![CAT] = Me.CatNum
Forms![RGAData]![FrSer#] = Me.DateCode
Forms![RGAData]![Comm] = Me.EvalDesc
I would do this:
Dim lRGA As Long
Dim lCat As Long
Dim dDateCode As Date
Dim sEval As String
Dim sLink As String
lRGA = Me.RGANum
lCat = Me.CatNum
dDateCode = Me.DateCode
sEval = Me.EvalDesc
sLink = "[RGANum] = " & lRGA & " AND [CatNum] = " & lCat & _
" AND [DateCode] = " & "#" & dDateCode & "#" & _
" AND [EvalDesc] = " & "'" & sEval & "'"
DoCmd.OpenForm "RGAData", acNormal, , sLink
You will have to check the syntax of the DoCmd to make sure you put sLink in the WHERE section.
Does this work?
Also, I would take the variables for the MsgBox seperately and then pass them to the MsgBox with formatting so the user doesn't get two message boxes.
mmcdonal
|
|

July 5th, 2006, 09:37 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have altered my code so that it reflects exactly what you have above, with the exception of variable formats. I am using the msgbox to simply display the information that I want the code to read and react on. As you had indicated before, I am receiving 15 buttons, one for each record, which is what I want. Even when coding as you had indicated, the msgbox is only displaying the information for the first record returned when any of the 15 buttons is "clicked". I want the message box to display the information for only the record it is being generated with. If I click button 15, I want to see the CAT number for record 15. Instead, when I click button 15 (or any other button), it displays the CAT number for record 1 only.
The problem is not getting the form "RGAData" to pop-up with pre-populated cells. The problem is that no matter which records button I use, it always populates with information from record 1.
KellJW
|
|

July 5th, 2006, 09:40 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
I think I would have to see the continuous form at this point. Using the code above, I get the next form to open with only the selected record.
mmcdonal
|
|

July 5th, 2006, 11:21 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Can I email you the Access file, it is 10,500KB?
|
|

July 5th, 2006, 11:51 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Can you create a copy of it, then delete most of the data, and then mail me one about 2MB?
mmcdonal
|
|
 |