A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Adding selected data (using code atached to cmd button from a form) to a table



 
 
Thread Tools Display Modes
  #1  
Old May 26th, 2004, 12:12 PM
Chris
external usenet poster
 
Posts: n/a
Default Adding selected data (using code atached to cmd button from a form) to a table

In a form, i have a command button with a code like below, which is making a
sellection from a query (which represent the current state of a stock) to
display it in a form. How can I make to add these selected data to a table
(the table of withdrawings from the stock), instead displaying in a form? In
fact I need a method to make the exits from the stock, without permiting to
withdraw a material wich does not exist in the stock.
I would apreciate any help!
Thank you!

The code:
Private Sub cmbOpenForm_Click()
On Error GoTo Err_cmbOpenForm_Click

Dim stDocName As String
Dim Msg1 As String

Dim DenumireCrit As String
Dim MyDenumire As String

Dim DimensiuniCrit As String
Dim MyDimensiuni As String

Dim CalitateaCrit As String
Dim MyCalitatea As String

Dim DenumireField As String
Dim DimensiuniField As String
Dim CalitateaField As String

Dim Counter As Integer

Dim Crit As String

stDocName = "Stoc11"
'the form you are going to open
DenumireField = "[Denumire]"
'the name of your Denumire field in the form you are going to open
DimensiuniField = "[dimensiuni]"
'name of your Dimensiuni field
CalitateaField = "[Calitatea]"
'name of the field you will filter with like

'see which fields you need to include in your string by checking their
'checkboxes. If one is blank, end sub
Msg1 = "Daca selectati un criteriu, asigurati-va ca sunt date
introduse/selectate in caseta corespunzatoare."

If IsNull(Me.cboDenumire) And Me.ChkDenumire = True Then
msgbox Msg1
Exit Sub
End If

If IsNull(Me.cboDimensiuni) And Me.ChkDimensiuni = True Then
msgbox Msg1
Exit Sub
End If

If IsNull(Me.cboCalitatea) And Me.chkCalitatea = True Then
msgbox Msg1
Exit Sub
End If
Counter = 0
If Me.ChkDenumire = True Then
'include what is in cboDenumire
MyDenumire = Me.cboDenumire
DenumireCrit = DenumireField & " Like '*" & MyDenumire & "*'"
Counter = Counter + 1
Else
DenumireCrit = ""
End If

If Me.ChkDimensiuni = True Then
MyDimensiuni = Me.cboDimensiuni
DimensiuniCrit = DimensiuniField & " Like '" & MyDimensiuni & "'"
Counter = Counter + 1
Else
DimensiuniCrit = ""
End If

If Me.chkCalitatea = True Then
MyCalitatea = Me.cboCalitatea
CalitateaCrit = CalitateaField & " Like '*" & MyCalitatea & "*'"
Counter = Counter + 1
Else
CalitateaCrit = ""
End If


Select Case Counter

Case 1
'only one criteria has been chosen
If Me.ChkDenumire = True Then
'that field was chosen
Crit = DenumireCrit
End If

If Me.ChkDimensiuni = True Then
Crit = DimensiuniCrit
End If

If Me.chkCalitatea = True Then
Crit = CalitateaCrit
End If


Case 2
'if 2 fields have been chosen, identify which 2

If Me.ChkDenumire = True And Me.ChkDimensiuni = True Then
Crit = DenumireCrit & " AND " & DimensiuniCrit
End If

If Me.ChkDenumire = True And Me.chkCalitatea = True Then
Crit = DenumireCrit & " AND " & CalitateaCrit
End If

If Me.ChkDimensiuni = True And Me.chkCalitatea = True Then
Crit = DimensiuniCrit & " AND " & CalitateaCrit
End If

Case 3
'all 3 fields have been ticked
Crit = DenumireCrit & " AND " & DimensiuniCrit & " AND " & CalitateaCrit
End Select


DoCmd.OpenForm stDocName, acNormal, , Crit

Exit_cmbOpenForm_Click:
Exit Sub

Err_cmbOpenForm_Click:
msgbox Err.Description
Resume Exit_cmbOpenForm_Click


End Sub





 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:27 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.