Solved

How can I get a value from a Form by coding??

Posted on 2004-04-21
12
325 Views
Last Modified: 2006-11-17
Here is part of the coding:

Private Sub Edit_Click()

stDocName = "DataEntry_Staff_Edit"

stStaffCode = (How can I get a value from form?? let's say I would like to get the staff code from a text box "StaffCode" from a form "DataEntry_Staff")

DoCmd.OpenForm stDocName, acFormEdit, acWindowNormal

End Sub
0
Comment
Question by:ryan0107
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 6

Accepted Solution

by:
nathaniel earned 500 total points
ID: 10885728
In Access2000 try these:

Private Sub Edit_Click()

  stDocName = "DataEntry_Staff_Edit"

  stStaffCode = [DataEntry_Staff]!StaffCode

  DoCmd.OpenForm stDocName, acFormEdit, acWindowNormal

End Sub
0
 

Author Comment

by:ryan0107
ID: 10885754
Sorry, then how can I use   DoCmd.OpenForm to open the stDocName and with filtering the stStaffCode??
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 10885756
Try this:

in a module add this:

Public Function ifIsLoaded(ByVal strFormName As String) As Integer
'Returns a 0 if form is not open or a -1 if Open
    If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0 Then
        If Forms(strFormName).CurrentView <> 0 Then
            ifIsLoaded = True
        End If
    End If
End Function

then to check the value, use this:

Private Sub Command1_Click()
    If ifIsLoaded("DataEntry_Staff_Edit") = 0 Then
        MsgBox "DataEntry_Staff_Edit Not loaded!"
    Else
        MsgBox Form_DataEntry_Staff_Edit.Controls("StaffCode").Value
    End If
End Sub
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 52

Expert Comment

by:Ryan Chong
ID: 10885763
DoCmd.OpenForm formname[, view][, filtername][, wherecondition][, datamode][, windowmode][, openargs]

Example:

DoCmd.OpenForm "DataEntry_Staff_Edit", , ,"stStaffCode= '" & Form_DataEntry_Staff_Edit.Controls("StaffCode").Value & "'"
0
 
LVL 6

Expert Comment

by:nathaniel
ID: 10885814
to apply it as filter in opening form, you may try this:

CHANGE
DoCmd.OpenForm stDocName, acFormEdit, acWindowNormal

TO:

'if stStaffCode is of string type:
DoCmd.OpenForm stDocName,,,"stStaffCode=" & """" & stStaffCode & """", acFormEdit, acWindowNormal


'if stStaffCode is of number type:
DoCmd.OpenForm stDocName,,,"stStaffCode=" & stStaffCode, acFormEdit, acWindowNormal

hope this helps,
0
 

Author Comment

by:ryan0107
ID: 10885826
Sorry,  when I use this code:

DoCmd.OpenForm "DataEntry_Staff_Edit", , ,"stStaffCode= '" & Form_DataEntry_Staff_Edit.Controls("StaffCode").Value & "'"

An error message was displayed as follow:

"Run Time Error 3075
Syntax Error (missing operator) in query expression 'stStaffCode=1234'"

Can you help me to solve it??
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 10885900
>>"Run Time Error 3075
Syntax Error (missing operator) in query expression 'stStaffCode=1234'"

is you missing something? >>'stStaffCode=1234'", this definitely is wrong! try:

"stStaffCode= '" & Form_DataEntry_Staff_Edit.Controls("StaffCode").Value & "'"

stStaffCode='1234'"

or

"stStaffCode= " & Form_DataEntry_Staff_Edit.Controls("StaffCode").Value

stStaffCode=1234"
0
 

Author Comment

by:ryan0107
ID: 10885951
Basically,  here is the code:

Private Sub Edit_Click()
stDocName = "DataEntry_Staff_Edit"
stStaffCode = [Forms]![DataEntry_Staff]![Staff Code]
DoCmd.OpenForm stDocName, , , "Staff Code= " & stStaffCode, acFormEdit

End Sub

An error message shown as :

>>Run Time Error 3075
Syntax Error (missing operator) in query expression 'Staff Code=1234'

Any idea can give me??
0
 
LVL 6

Expert Comment

by:nathaniel
ID: 10886042
We'll start with this first:

is the stStaffCode a number type of string type?
0
 
LVL 6

Expert Comment

by:nathaniel
ID: 10886098
We'll start with this first:

is the stStaffCode a number type or string type?

if string type, use:

DoCmd.OpenForm stDocName, , , "Staff Code= " & """" & stStaffCode & """", acFormEdit

if not, use:

DoCmd.OpenForm stDocName, , , "Staff Code= " & stStaffCode, acFormEdit

0
 

Author Comment

by:ryan0107
ID: 10887194
Thanks.  I can open the form successfully... but can't filter just that staffcode record from my table.  All records were extracted from a table just as usual.

Basically,  I want to use above codes to open a new form with just one related profile (making use of Staff Code) and then go right ahead for edit.

Do you think my coding is right??

Sorry I have too many questions coz I'm just new to Access
0
 
LVL 6

Expert Comment

by:nathaniel
ID: 10887402
That's ok ryan don't give up!

If you can open the form successfully, then we now need to fix the condition part.

try this one first:

msgbox stStaffCode
DoCmd.OpenForm stDocName, , , "[Staff Code] = " & stStaffCode, acFormEdit

explanation:
the msgbox.. will let you know if you are getting a value

let me know if it works,



0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question