Hi Guys,
it is me, once again
I have problem with adding values into my subform using vba code.
It is very difficult issue.
in attachment please see the sample database.
Instruction:
Log into database using Login: ljar01
Password: test
tbl_Korekty form will be displayed.
And now fill all required fields like below:

4 fields on the right from subform are fulfilled automatically.
And qlikbutton with magic wand symbol - subform will be fullfiled:

This button is used code:
Code:
Private Sub Button_MonDate_Click()
Dim dteDate As Date
Dim dteDateCounter As Date
Dim dteDateEnd As Date
Dim sqlString As String
Dim counter As Byte
Dim Money_value As Currency
Dim LiczbaRaportow As Variant
Dim Cause_ID_FK As Long
Dim Korekty_ID_FK As Long
Dim Slownik_ID_FK As Variant
Dim Status_name As Long
If IsNull(Me.Com_przyczyna) Or IsNull(Me.Com_topic) Or _
IsNull(Me.Com_status) Or _
IsNull(Me.TextBoxDfrom) Or IsNull(Me.TextBoxDTo) Or _
IsNull(Me.Txb_slownik_id) Then
MsgBox "Wszystkie pola muszą zostać wypełnione", _
vbCritical, _
"Anulowanie akcji"
Me.SetFocus
Exit Sub
End If
dteDate = Format([TextBoxDfrom], "MM/YYYY")
dteDateEnd = Format([TextBoxDTo], "MM/YYYY")
If dteDateEnd < dteDate Then
MsgBox "Data korekty DO powinna być większa niż Data korekty OD)"
End If
dteDateCounter = dteDate
While dteDateCounter <= dteDateEnd
counter = counter + 1
dteDateCounter = DateAdd("m", 1, dteDateCounter)
Wend
LiczbaRaportow = Nz(DLookup("Liczba_raportow", "tbl_Causes", "Cause='" & Me.Com_przyczyna.Column(1) & "'"), 0)
If LiczbaRaportow = 0 Then
LiczbaRaportow = Null
End If
Cause_ID_FK = Com_status.Column(0)
With Me.[NowaOby]
.SetFocus
.Form![Status_date].SetFocus
.Form!Cause_ID_FK = Cause_ID_FK
On Error Resume Next
RunCommand acCmdRecordsGoToNew
On Error GoTo 0
.Form!Liczba_raportow = LiczbaRaportow
.Form!Status_date = Now()
.Form!Data_korekty = Now()
With Form_NowaOby
.Com_status_n = Com_status.Value
.Com_przyczyna_n = Com_przyczyna.Value
End With
DoCmd.RunCommand acCmdSaveRecord
End With
End Sub
here i am adding new record into subform.
Problem is when do you wnat to add another record, The code:
Code:
On Error Resume Next
RunCommand acCmdRecordsGoToNew
On Error GoTo 0
throw an error 2501: "runcommand action was cancelled"
My goal is to give possibility to user in order to choose dates, for example 2017-10-01
To 2017-11-01 (2 calendars icons). And after clicking magic wand 2 records with 2 dates should be inserted into forms (All other data should be the same)
Why this is not working. How can i do it in other way?
Please help,
Thank you in advance,
Best Wishes,
Łukasz Jarych