Newbie struggling (1 Viewer)

Mcgregorbart

New member
Local time
Today, 05:57
Joined
Jul 30, 2010
Messages
11
I have a TEMP table and added field called Barcode, I have a command button which produces a report however when ever I press it I get the following error? What do I need to add to get it to read this field please
DoCmd.RunSQL "INSERT INTO temp VALUES('" & Me.Address & "','" & i & "','" & Me.Of_Number & "')"
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:57
Joined
Oct 29, 2018
Messages
21,467
Hi. What was the error?
 

Mcgregorbart

New member
Local time
Today, 05:57
Joined
Jul 30, 2010
Messages
11
Hi. What was the error?
Run time error 3346
Number of query values and destination fields are not the same

Both Query and Field in table are spelt correctly
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:57
Joined
Oct 29, 2018
Messages
21,467
Run time error 3346
Number of query values and destination fields are not the same

Both Query and Field in table are spelt correctly
Okay, try specifying the fields then. For example,

INSERT INTO temp (Field1, Field2, Field3) VALUES (Value1, Value2, Value3)
 

Mcgregorbart

New member
Local time
Today, 05:57
Joined
Jul 30, 2010
Messages
11
Okay, try specifying the fields then. For example,

INSERT INTO temp (Field1, Field2, Field3) VALUES (Value1, Value2, Value3)
Thanks for your patience
Hi no joy I am afraid this is the full code for that command button, The line in bold text gets highlighted in yellow?



Private Sub Btn_Generate_Click()

Dim i As Integer
Dim RS As Recordset

'Check the form has been filled in correctly

'Check that start and end numbers have been entered
If IsNull(Me.Start_Number) Or IsNull(Me.End_Number) Then
MsgBox "You must have a value in the start number and end number boxes"
End
'Check that start and end numbers are valid numbers
ElseIf IsNumeric(Me.Start_Number) = False Or IsNumeric(Me.End_Number) = False Then
MsgBox "Only numbers are allowed in the start number and end number boxes)"
End

End If

'Check for apostrophes and replace with double apostrophes to avoid an error when executing the RUNSQL statement
Me.Address = Replace(Me.Address, "'", "''")


DoCmd.SetWarnings False

'Clear the Temp table
DoCmd.RunSQL "DELETE * FROM temp"

'Set the number of labels to produce
i = Me.Start_Number

'Keep adding new records starting at the provided start number until the end number is reached
While i <= Me.End_Number

DoCmd.RunSQL "INSERT INTO temp VALUES('" & Me.Address & "','" & i & "','" & Me.Of_Number & "')"
i = i + 1


Wend

DoCmd.SetWarnings True

'Generate the Label Sheet
DoCmd.OpenReport "Seed Labels correct spacing numbered", acViewPreview


End Sub
 

Mcgregorbart

New member
Local time
Today, 05:57
Joined
Jul 30, 2010
Messages
11
copy of database
 

Attachments

  • copy Label Generator Samsung Printer 101118version.accdb
    640 KB · Views: 140

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 23:57
Joined
Feb 28, 2001
Messages
27,172
Be aware that it is considered a bit rude to cross-post without telling us about it. However, clearly you are new to the forum and might not have yet seen that request. We don't ignore such requests, but we dislike them as they offer an opportunity for us to waste our time on a question already answered elsewhere.

Having now given you the obligatory discussion on cross-posting, your code has an error at the X that I have inserted:
DoCmd.RunSQL "INSERT INTO temp X VALUES('" & Me.Address & "','" & i & "','" & Me.Of_Number & "')"

The problem is that at the X you must have a parenthetically enclosed list of the field names in table temp where you want those values to be stored. Your syntax error is that you have 0 destination fields but do not have 0 values to go with it. I count three values so you need to name three target fields.
 

Mcgregorbart

New member
Local time
Today, 05:57
Joined
Jul 30, 2010
Messages
11
Be aware that it is considered a bit rude to cross-post without telling us about it. However, clearly you are new to the forum and might not have yet seen that request. We don't ignore such requests, but we dislike them as they offer an opportunity for us to waste our time on a question already answered elsewhere.

Having now given you the obligatory discussion on cross-posting, your code has an error at the X that I have inserted:
DoCmd.RunSQL "INSERT INTO temp X VALUES('" & Me.Address & "','" & i & "','" & Me.Of_Number & "')"

The problem is that at the X you must have a parenthetically enclosed list of the field names in table temp where you want those values to be stored. Your syntax error is that you have 0 destination fields but do not have 0 values to go with it. I count three values so you need to name three target fields.
Thank you and my apologies for the cross post I am now aware and shall follow etiquette going forward
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:57
Joined
May 7, 2009
Messages
19,233
you must specify the Field names if your table field count is not Same as the in the Query.
or if the sequence of fields are different:
Code:
    'Keep adding new records starting at the provided start number until the end number is reached
    While i <= Me.End_Number

        DoCmd.RunSQL "INSERT INTO [Temp] ([Address], [Lable_No], [Max_Labels]) VALUES ('" & Me.Address & "','" & i & "','" & Me.Of_Number & "')"
        i = i + 1
        
    Wend
 

Mcgregorbart

New member
Local time
Today, 05:57
Joined
Jul 30, 2010
Messages
11
Thank you all for your input much appreciated took a while but with your help above sorted problem thanks again all and stay safe ;)
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:57
Joined
Oct 29, 2018
Messages
21,467
Thank you all for your input much appreciated took a while but with your help above sorted problem thanks again all and stay safe ;)
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom