PC Review


Reply
Thread Tools Rate Thread

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

 
 
Chris
Guest
Posts: n/a
 
      26th May 2004
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





 
Reply With Quote
 
 
 
 
Nikita Marchant
Guest
Posts: n/a
 
      12th Jun 2004
in article #(E-Mail Removed), Chris at (E-Mail Removed) wrote on
26/05/04 13:12:

> 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
>

kghjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding selected data (using code atached to cmd button from a form) to a table Chris Microsoft Access 1 12th Jun 2004 02:27 PM
Adding selected data (using code atached to cmd button from a form) to a table Chris Microsoft Access Queries 1 12th Jun 2004 02:27 PM
Adding selected data (using code atached to cmd button from a form) to a table Chris Microsoft Access Macros 1 12th Jun 2004 02:27 PM
Adding selected data (using code atached to cmd button from a form) to a table Chris Microsoft Access Forms 1 12th Jun 2004 02:27 PM
Adding selected data (using code atached to cmd button from a form) to a table Chris Microsoft Access Form Coding 1 12th Jun 2004 02:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:23 AM.